选择框checkbox

选择框checkbox

<!DOCTYPE html>
<html>
<head>
  <style>
  a{display:inline-block;}
  </style>
  <script src="http://libs.useso.com/js/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<a data-command="check-true">全选</a>
<a data-command="check-false">反选</a>
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
 <script>
$(function(){
    $('[data-command="check-true"]').click(function(){
        $('input[type="checkbox"]').attr("checked",true)
    });
    $('[data-command="check-false"]').click(function(){
        $('input[type="checkbox"]').each(function(){
            $(this).attr("checked",!$(this).attr("checked"));
        });
    })
});
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/wzzl/p/5390831.html