使用Jquery属性禁用多个复选框 [英] Disable the Multiple Checkboxs using Jquery Attribute
问题描述
Hai all,
我的复选框列表中包含相同的ID,
< input id ='CheckBox1'class ='chkbxq'type ='checkbox'name ='chkOrder'/>
< input id ='CheckBox1'class ='chkbxq'type ='checkbox'name ='chkOrder'/>
< input id ='CheckBox1' class ='chkbxq'type ='checkbox'name ='chkOrder'/>
< input id ='CheckBox1'class ='chkbxq'type ='checkbox'name ='chkOrder'/ >
我希望使用ID隐藏此复选框,我试过这段代码 $(#CheckBox1)。attr(disabled,true ); 但第一个复选框仅禁用其他复选框已启用。我能做些什么来隐藏这四个复选框请给我们任何帮助。
问候
Sampath
(#CheckBox1)。attr(disabled,true); 但第一个复选框仅禁用其他复选框已启用。我能做些什么来隐藏这四个复选框请给我们任何帮助。
问候
Sampath
< blockquote>你的代码
(#CheckBox1)。attr(disabled,true);
不起作用,因为jQuery只需要一个匹配特定ID的元素。您的HTML无效;元素的ID必须是唯一的。更改HTML并让jQuery选择器使用类或name属性。您还应该使用 prop()
而不是 attr()
来禁用它们:
Hai all,
I have the list of checkbox with same ID like this,
<input id='CheckBox1' class='chkbxq' type='checkbox' name='chkOrder' />
<input id='CheckBox1' class='chkbxq' type='checkbox' name='chkOrder' />
<input id='CheckBox1' class='chkbxq' type='checkbox' name='chkOrder' />
<input id='CheckBox1' class='chkbxq' type='checkbox' name='chkOrder' />
and i want to hide this checkbox using ID, i tried this code $("#CheckBox1").attr("disabled", true); but the first checkbox only disabled others are enabled. what can i do for hide these all the four checkboxes any help please.
Regards
Sampath解决方案("#CheckBox1").attr("disabled", true); but the first checkbox only disabled others are enabled. what can i do for hide these all the four checkboxes any help please.
Regards
Sampath
Your code
("#CheckBox1").attr("disabled", true);
doesn't work because jQuery expects only one element matching a specific ID. Your HTML is invalid; the IDs of elements need to be unique. Change your HTML and have the jQuery selector use a class or the "name" attribute. You should also be disabling them with prop()
instead of attr()
:
这篇关于使用Jquery属性禁用多个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!