Home  >  Article  >  Web Front-end  >  Simple and practical example of selecting all and inverting the selection button_jquery

Simple and practical example of selecting all and inverting the selection button_jquery

WBOY
WBOYOriginal
2016-05-16 17:19:361262browse
Copy code The code is as follows:

//Select all button processing
$(function(){
//Click to select all
$("#checkAll").click(function () {//When clicking on the select all box
var flag = $("#checkAll").is(" :checked"); // Determine the status of the select all button
var checkItems=document.getElementsByName("checkItem");
for(var i=0;i checkItems[i].checked = flag;
}
});
//Click on the sub-item
$("input:checkbox[name='checkItem']").each(function( ){
$(this).click(function(){
if($("input:checkbox[name='checkItem']:checked").length==$("input:checkbox[name ='checkItem']").length){
document.getElementById("checkAll").checked = true;
}else{
document.getElementById("checkAll").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