1. Basic functions:
Requirements: click on the selection, the selection buttons check box under all selected, otherwise, all don't choose
According to the ID selection button, back off function within the binding click events, events in $(" # check input ") that is the use of the hierarchy selector to get all the checkboxes prop and give him the binding event
With two parameters method is used the first parameter is the checked attribute the second parameter of true or false. Note: the check boxes for many kinds of this only demonstrates one way!
$(function () {
$(" # che_quan "). Click (function () {
$(" # check input "). Prop (" checked ", $(" # che_quan "), is (" : checked "));
});
});
2. Strengthen
Requirements: when one of the check box is not selected, all button is not selected, when the check box full selected the selection button and select the
Note that $(". Chec: checked "). The length; That using class selectors to select all of the class of the same check box, the direct connect (attention: checked). Chec: checked the middle don't have space space system will automatically identify he take subset
$(function () {
$(" # che_quan "). Click (function () {
$(" # check input "). Prop (" checked ", $(" # che_quan "), is (" : checked "));
});
$(" # check input "). Click (function () {
Var len=$(". Chec ".) length;
Var sum=$(". Chec: checked "). The length;
If (len==sum) {
$(" # che_quan "). Prop (" checked ", true);
} else {
$(" # che_quan "). Prop (" checked ", false);
}
})
});
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
$(function () {
$(" # che_quan "). Click (function () {
$(" # check input "). Prop (" checked ", $(" # che_quan "), is (" : checked "));
});
$(" # check input "). Click (function () {
Var len=$(". Chec ".) length;
Var sum=$(". Chec: checked "). The length;
If (len==sum) {
$(" # che_quan "). Prop (" checked ", true);
} else {
$(" # che_quan "). Prop (" checked ", false);
}
})
});
</script>
<body>