<script type="text/javascript">
$(
function(){
//全选
$("#CheckedAll").click(function(){
$(
'[name=items]:checkbox').attr("checked", this.checked );
});
$(
'[name=items]:checkbox').click(function(){
//定义一个临时变量,避免重复使用同一个选择器选择页面中的元素,提升程序效率。
var $tmp=$('[name=items]:checkbox');
//用filter方法筛选出选中的复选框。并直接给CheckedAll赋值。
$('#CheckedAll').attr('checked', $tmp.length==$tmp.filter(':checked').length);
});

//输出值
$("#send").click(function(){
var str="你选中的是:\r\n";
$(
'[name=items]:checkbox:checked').each(function(){
str
+=$(this).val()+"\r\n";
})
alert(str);
});
});
</script>
</head>

<body>
<form method="post" action="">
<b>你爱好的运动是?</b><br/>
<input type="checkbox" id="CheckedAll" />全选/全不选<br/>
<input type="checkbox" name="items" value="足球"/>足球
<input type="checkbox" name="items" value="篮球"/>篮球
<input type="checkbox" name="items" value="羽毛球"/>羽毛球
<input type="checkbox" name="items" value="乒乓球"/>乒乓球<br/>
<input type="button" id="send" value="提 交"/>
</form>

</body>

相关文章:

  • 2021-05-20
  • 2021-10-29
  • 2022-12-23
  • 2021-06-30
  • 2021-12-11
  • 2021-12-15
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2022-12-23
  • 2021-05-22
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-09-27
相关资源
相似解决方案