Home  >  Article  >  Web Front-end  >  Jquery CheckBox select all method code with js checkbox select all inverse code_jquery

Jquery CheckBox select all method code with js checkbox select all inverse code_jquery

WBOY
WBOYOriginal
2016-05-16 18:25:32986browse
The jquery method is as follows:
Copy code The code is as follows:

function CheckAll (val) {
$("input[name='chkJob']").each(function() {
this.checked = val;
});
$("#chkAll ").attr("checked", val);//Set the select-all button state
}

val This parameter passes the selection state of the select-all button
name= 'chkJob' is the name of the checkbox in the list
chkAll is the name of the select all button
I like the simplicity and clarity of Jquery...
There is really a gap compared to writing in JavaScript!
eg:
javascript select all and inverse select code
Copy code The code is as follows:

//Select all
function checkall() {
var all = document.getElementsByTagName("input");
for (var i = 0; i < all.length ; i ) {
if (all[i].type == "checkbox") {
all[i].checked = true;
}
}
}
/ /Inverse selection
function checknull() {
var all = document.getElementsByTagName("input");
for (var i = 0; i < all.length; i ) {
if ( all[i].type == "checkbox") {
all[i].checked = false;
}
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn