你的位置:首页 > Java教程

[Java教程]checkbox实现全选全不选

1.jQuery实现checkbox全选全不选<!DOCTYPE html><head runat="server"><title>jQuery实现CheckBox全选、全不选</title><meta charset="utf-8"><script src="jquery-3.1.1.min.js"></script> <script type="text/javascript">$(function() {$("#checkAll").click(function() {$('input[name="subBox"]').attr("checked",this.checked); });var $subBox = $("input[name='subBox']");$subBox.click(function(){$("#checkAll").attr("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);});});</script></head><body><div><input id="checkAll" type="checkbox" />全选<input name="subBox" type="checkbox" />项1<input name="subBox" type="checkbox" />项2<input name="subBox" type="checkbox" />项3<input name="subBox" type="checkbox" />项4</div></body></html>