在网站建设中;让复选框所有选中和所有取消是比较经常使用的;下面就介绍如何用一句话搞定全选功能;php
其实很简单;那就是使用盘点jQuery弃用的函数这篇文章中最后一段代码;html
好了,我要介绍的方法讲完了;函数
好吧,别砸鸡蛋;我是开个玩笑;代码在下面网站
JavaScript部分:this
function checkAll(obj){ $("#box input[type='checkbox']").prop('checked', $(obj).prop('checked')); }
html部分:code
<div id="box"> <input type="checkbox" onclick="checkAll(this)">全选<br><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> <input type="checkbox"><br> </div>
本文为白俊遥原创文章,转载无需和我联系,但请注明来自白俊遥博客baijunyao.com htm