现在的位置: 首页 > 综合 > 正文

jQuery实现CheckBox全选、全不选

2018年05月06日 ⁄ 综合 ⁄ 共 832字 ⁄ 字号 评论关闭

<!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>Index</title>

     <script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>    <script type="text/javascript">
        $(
function() {
            $(
"#CheckAll").click(function
() {
               
var flag = $(this).attr("checked"
);
                $(
"[name=subBox]:checkbox").each(function
() {
                    $(
this).attr("checked"
, flag);
                })
            })
        })
   
</script>

</head>
<body>
   
<div>
       
<input id="CheckAll" type="checkbox" />
       
<input name="subBox" type="checkbox" />
       
<input name="subBox" type="checkbox" />
       
<input name="subBox" type="checkbox" />
       
<input name="subBox" type="checkbox" />
   
</div>
</body>
</html>

抱歉!评论已关闭.