日期:2014-05-16  浏览次数:20435 次

checkbox至多选一个的问题,想实现只能选一个和全都不选的功能,但是现在只能实现单选,全都不选实现不了,求帮忙
<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>

------解决方案--------------------
 $(function () {
            var allBox = $(":checkbox");
            allBox.click(function () {
               if(this.checked){
                   allBox.removeAttr("checked");
                   $(this).attr("checked", "checked");
                 }
            });
        });
------解决方案--------------------
 $(function () {
            var allBox = $(":checkbox");
            allBox.click(function () {
               if(this.checked 
------解决方案--------------------
 this.checked=='checked'){
                   allBox.removeAttr("checked");
                   $(this).attr("checked", "checked");
                 }
            });
        });