两行代码搞定checkbox全选

字号+ 编辑: 国内TP粉 修订: 秃顶萧峰 来源: ThinkPHP 2023-09-06 我要说两句(0)

网络转载。

简简单单两行代码搞定checkbox全选和取消全选

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>全选测试</title>
<script type=text/javascript src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<input type="checkbox" id="quanxuan" />全选<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
</body>
</html>
<script type="text/javascript">
$("#quanxuan").click(function(){
var xz = $(this).prop("checked");// 判断全选按钮的选中状态
var ck = $(".qx").prop("checked",xz);  // 让class名为qx的选项的选中状态和全选按钮的选中状态一致。
});
</script>


<sc
ript type=text/ja
vasc
ript src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></sc
ript>
</head>
<body>
<input type="checkbox" id="quanxuan" />全选<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
<input type="checkbox" class="qx" />aa<br />
</body>
</html>
<script type="text/javascript">
$("#quanxuan").click(function(){
var xz = $(this).prop("checked");/ /判断全选按钮的选中状态
var ck = $(".qx").prop("checked",xz);  // 让class名为qx的选项的选中状态和全选按钮的选中状态一致。
});
</script>
$("#quanxuan").click(function(){
var xz = $(this).prop("checked");// 判断全选按钮的选中状态
var ck = $(".qx").prop("checked",xz);  // 让class名为qx的选项的选中状态和全选按钮的选中状态一致。
});
</script>


阅完此文,您的感想如何?
  • 有用

    0

  • 没用

    0

  • 开心

    0

  • 愤怒

    0

  • 可怜

    0

1.如文章侵犯了您的版权,请发邮件通知本站,该文章将在24小时内删除;
2.本站标注原创的文章,转发时烦请注明来源;
3.交流群: PHP+JS聊天群

相关课文
  • 上传自定义文件的时候查如何填写上传表单中的access, mimeType等字段值

  • HTML5+CSS3——第6章 HTML5表单标签,与浏览者交互

  • HTML5+CSS3——第5章 HTML5图片、链接及表格标签

  • HTML5+CSS3——第4章 HTML5列表标签

我要说说
网上宾友点评