Home > Web Front-end > JS Tutorial > jQuery's selection of all (no selection of all) is to obtain the selected value. Introduction_jquery

jQuery's selection of all (no selection of all) is to obtain the selected value. Introduction_jquery

WBOY
Release: 2016-05-16 17:15:56
Original
1385 people have browsed it

Page code

Copy code The code is as follows:


All


< input type="checkbox" name="checkbox" value="day" />day
empty
< input type="checkbox" name="checkbox" value="fly" />fly
come
< input type="checkbox" name="checkbox" value="五" />五
piece
< input type="checkbox" name="checkbox" value="Word" />Word
This
< input type="checkbox" name="checkbox" value="Both" />Both
No
< input type="checkbox" name="checkbox" value="Calculation" />Calculation
Things






Code in js
Copy the code The code is as follows:

/*js part
* Bind batch selected/unselected
* Example
*/

$(function () {
$("#checkall").click(function () {
var stu = $(this).attr("checked");
checkAll (stu);
})
$("input[name='checkbox']").click(function () {
uncheckAll();
})
})
function checkAll(status) {
$("input[name='checkbox']").each(function () {
$(this).attr("checked");
$ (this).attr("checked", status);
})
}

function uncheckAll() {
alert($("input[name='checkbox']: checked").length);
if ($("input[name='checkbox']:checked").length == $("input[name='checkbox']").length) {
$("#checkall").attr("checked",true);
}
else {
$("#checkall").attr("checked", 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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template