Home > Web Front-end > JS Tutorial > Convenient and practical jQuery checkbox checkbox select all function simple example_jquery

Convenient and practical jQuery checkbox checkbox select all function simple example_jquery

WBOY
Release: 2016-05-16 17:20:32
Original
936 people have browsed it

Copy code The code is as follows:

// Main checkbox
// Sub-checkbox item



Copy code The code is as follows:

var $ckAll = $("input[name=' ckAll']");
var $ckItm = $("input[name='ckItm']");
var len = $ckItm.length;
$ckAll.click(function() {
// Get the current selected status of $ckAll. If selected, other sub-checkboxes will be selected, otherwise they will be cancelled.
$ckItm.prop('checked',this.checked);
});
$ckItm.click(function() {
// Bind the judgment event to b
var b=$ckItm.filter(":checked").length==len;// When the selected The number of sub-checkboxes is equal to the total number, and the main checkbox will be selected
// Determine through ternary operation
var flag=$ckAll.prop("checked",b?true:false) ;
});
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template