CheckBoxFor 呈现同名的隐藏字段 ( and for good reason )
我需要在页面加载时根据复选框的值启用/禁用一些其他输入字段。但是,我无法正确使用 JQuery 选择器。我的函数最终触发了两次,因为选择器同时获取了复选框和隐藏输入字段。
这是我尝试过的方法,但都不起作用:
$('input[name$="Selected",type=checkbox]').each(function (){
alert('here ' + this.name);
EnableOrderItemDropDowns(this);
});
$('input[name$="Selected"],:checkbox').each(function (){
alert('here ' + this.name);
EnableOrderItemDropDowns(this);
});
这两种方法都不起作用。后一种方法仍然不会仅过滤到 CheckBox 输入,因此对 EnableOrderItemDropDowns 的调用仍会触发两次。
最佳答案
$('input[name$="Selected"][type="checkbox"]')
关于jquery - 在MVC3中使用CheckBoxFor时,如何使用JQuery仅选择CheckBox INPUT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8099286/