ddxiami

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2866|回复: 0

[Jquery] jQuery实现CheckBox全选、全不选

[复制链接]
发表于 2014-12-14 18:22:40 | 显示全部楼层 |阅读模式
test.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery实现CheckBox全选、全不选</title>
<script src="jquery.js" type="text/javascript"></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>
<?php var_dump($_POST['subBox']);?>
<form action="" method="post">
    <div>
        <input id="checkAll" type="checkbox" />全选
        <input name="subBox[]" type="checkbox" value="1"/>项1
        <input name="subBox[]" type="checkbox" value="2"/>项2
        <input name="subBox[]" type="checkbox" value="3"/>项3
        <input name="subBox[]" type="checkbox" value="4"/>项4
    </div>
        <input type="submit" name="submit">
</form>

</body>
</html>

jQuery实现CheckBox全选、全不选.rar

14.84 KB, 下载次数: 1264

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|技术文档库 ( 闽ICP备15017263号-2 )|网站地图

GMT+8, 2025-5-18 22:20 , Processed in 0.037288 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表