一行jQuery代码搞定checkbox 全选和全不选

在网站建设中;让复选框全部选中和全部取消是比较常用的;下面就介绍如何用一句话搞定全选功能;

其实很简单;那就是使用盘点jQuery弃用的函数这篇文章中最后一段代码;

好了,我要介绍的方法讲完了;

u=3644218134,974193839&fm=21&gp=0_副本.jpg

好吧,别砸鸡蛋;我是开个玩笑;代码在下面

JavaScript部分:

function checkAll(obj){
    $("#box input[type='checkbox']").prop('checked', $(obj).prop('checked'));
}

html部分:

<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>
原文地址:https://www.cnblogs.com/shuaibai123/p/4464490.html