<script type="text/javascript">
        $(function () {
            var allBox = $(":checkbox");
            allBox.click(function () {
                allBox.removeAttr("checked");
                $(this).attr("checked", "checked");
            });
        });
</script>
<div>
    <input type="checkbox" value="1"/>
    <input type="checkbox" value="2"/>
</div>

解决方案 »

  1.   

     $(function () {
                var allBox = $(":checkbox");
                allBox.click(function () {
                   if(this.checked){
                       allBox.removeAttr("checked");
                       $(this).attr("checked", "checked");
                     }
                });
            });
      

  2.   

     $(function () {
                var allBox = $(":checkbox");
                allBox.click(function () {
                   if(this.checked || this.checked=='checked'){
                       allBox.removeAttr("checked");
                       $(this).attr("checked", "checked");
                     }
                });
            });