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

作者:陈三顺子 日期:2021-08-13 10:43:38 点击:4376

在网站建设中;
让复选框全部选中和全部取消是比较常用的;
下面就介绍如何用一句话搞定全选功能;
其实很简单;
那就是使用盘点jQuery弃用的函数这篇文章中最后一段代码;
好了,我要介绍的方法讲完了;


好吧,
别砸鸡蛋;
我是开个玩笑;
代码在下面;
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>



评论 0 人参, 0 条评论