Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:15:561341browse

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);
}
}
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
Previous article:Summary of js letter case conversion implementation methods_javascript skillsNext article:Summary of js letter case conversion implementation methods_javascript skills

Related articles

See more