如何在jQuery选择器语句中访问<asp:Checkbox>
的class属性?
例如
<asp:CheckBox runat="server" ID="cbTest" Text="Cb Test" FieldName="1st Test Check Box" class="toggleBox"/>
这样:
$(':checkbox').toggleAttr("checked", true, false)
访问该复选框并将自定义函数应用于checked属性,但如果我想基于某个类进行过滤,我该如何基于该过程进行访问/过滤?
答案 0 :(得分:5)
<asp:checkbox>
呈现为<input type="checkbox" />
。因此,您可以使用element selector,然后使用:chekbox selector,然后使用class selector。
$("input:checkbox.toggleBox")
将为您提供所需的带有类名toggleBox的复选框。
<强> 注意 强>
$(':checkbox')
相当于$('*:checkbox')
,因此应使用$('input:checkbox')
。
答案 1 :(得分:0)
function chkbxch(valor) {
//$('.ChChecar input:checkbox').attr('checked', true);
$.each($('.Ch' + valor + ' input:checkbox'), function () {
if ($(this).attr('checked')) {
$(this).attr('checked', false);
} else {
$(this).attr('checked', true);
}
});
}