2010年4月20日 星期二

How to check if checkbox is checked using jQuery

There are 3 ways in jQuery to find a check box is checked or not.
view plaincopy to clipboardprint?
// First way
$('#checkBox').attr('checked');
// Second way
$('#edit-checkbox-id').is(':checked');
// Third way for jQuery 1.2
$("input[@type=checkbox][@checked]").each(
function() {
// Insert code here
}
);
// Third way == UPDATE jQuery 1.3
$("input[type=checkbox][checked]").each(
function() {
// Insert code here
}
);

First two methods return true or false. True if that particular checkbox was checked or false if it is not checked. The third method iterates though all checkboxes with checked attribute defined and performs some action.

摘自:http://cfmitrah.com/blog/post.cfm/how-to-check-if-checkbox-is-checked-using-jquery

沒有留言:

wibiya widget