我已经看到类似的解决方案符合我的要求,但没有完全符合我的要求。我对 jQuery 很陌生,不太了解它,无法弄清楚如何从每个解决方案中提取点滴内容,使其适合我。
我需要一个函数来检查 .NET 网格中的所有复选框,而不是页面上的其他复选框。需要检查的复选框的示例是:
<input id="GridView2_ctl09_chkSelect" type="checkbox" name="GridView2$ctl09$chkSelect" />
我需要 jQuery 函数来检查复选框 ID 末尾带有“chkSelect”的所有复选框。
这是我当前的“检查全部”复选框:
<input id="GridView2_ctl01_cbSelectAll" type="checkbox" name="GridView2$ctl01$cbSelectAll" onclick="selectAll(this);" />
谢谢!
特雷弗
最佳答案
描述
您可以使用 jQuery 的 Attribute Contains Word Selector
来获取 id 属性中带有 chkSelect
的所有元素。
示例
$("input[id~='chkSelect']").each(function() {
// $(this) is a element
});
您可以使用以下方法将 checked
属性设置为所有复选框
$("input[id~='chkSelect']").attr('checked', true);
或
$("input[id~='chkSelect']").each(function() {
// $(this) is a element
$(this).attr('checked', true);
});
更多信息
关于jQuery 通过部分名称检查所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9049577/