how do you access the class attribute of a <asp:Checkbox>
in a jQuery selector statement?
for example
<asp:CheckBox runat="server" ID="cbTest" Text="Cb Test" FieldName="1st Test Check 开发者_C百科Box" class="toggleBox"/>
this:
$(':checkbox').toggleAttr("checked", true, false)
accesses the checkbox and applies a custom function to the checked attribute but if i want to filter based on a certain class how do i access/filter based on that?
<asp:checkbox>
is rendered as <input type="checkbox" />
. So you can use a element selector followed by a :chekbox selector and then a class selector.
$("input:checkbox.toggleBox")
will get you the desired checkbox with class name toggleBox.
See class selector
Note
$(':checkbox')
is equivalent to $('*:checkbox')
, so $('input:checkbox')
should be used instead.
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);
}
});
}
精彩评论