【发布时间】:2011-11-12 04:07:33
【问题描述】:
CheckBoxFor 呈现一个同名的隐藏字段 (and for good reason)
我需要在页面加载时根据 CheckBox 的值启用/禁用其他一些 INPUT 字段。但是,我无法正确使用 JQuery 选择器。我的函数最终触发了两次,因为选择器同时获取了 CheckBox 和 Hidden 输入字段。
这是我尝试过的,但都不起作用:
$('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 的调用仍然会触发两次。
【问题讨论】:
-
再一次,解决方案在我发布到 StackOverflow 后立即呈现给我。哦,好吧。 ($('input[name$="Selected"]:not(:hidden)'))
标签: jquery asp.net-mvc-3