[英]jquery I want to disable a div within a form based on hidden field
I have the below hidden field and I want to disable all the elements within a specific div based on the value of the hidden field. 我有下面的隐藏字段,并且我想基于隐藏字段的值禁用特定div中的所有元素。
Here is the hidden field. 这是隐藏的字段。
<input type="hidden" id="addincidentval" name="addincidentval" value="Add Incident"/>
The div id is ehdiv
and it contains select, input text and check and textarea fields. div ID是
ehdiv
,它包含选择,输入文本以及check和textarea字段。
Below is the jquery function 下面是jQuery函数
$(function(){
var addinc = $("#addincidentval").val();
if(addinc =="Add Incident"){
$("#ehdiv *").disable();
}
})
use this jquery code 使用这个jQuery代码
$(function(){
var addinc = $("#addincidentval").val();
if(addinc =="Add Incident"){
$("#ehdiv *").prop("disabled",true);
}
})
$("#ehdiv").find('*').prop('disabled', true)
you can also try 你也可以尝试
$("#ehdiv :input").prop('disabled', true)
How to select ALL children (in any level) from a parent in jQuery? 如何从jQuery的父级中选择所有子级(任何级别)?
How to get all child inputs of a div element (jQuery) 如何获取div元素的所有子输入(jQuery)
:input
selects all input, textarea, select and button elements. :input
选择所有输入,文本区域,选择和按钮元素。 more: http://api.jquery.com/input-selector/ 更多: http : //api.jquery.com/input-selector/
$(function(){
var addinc = $("#addincidentval").val();
if(addinc =="Add Incident"){
$("#ehdiv :input").attr("disabled", true);
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.