首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

checkbox至多选一个的有关问题,想实现只能选一个和全都不选的功能,但是现在只能实现单选,全都不选实现不了,求帮忙

2013-09-28 
checkbox至多选一个的问题,想实现只能选一个和全都不选的功能,但是现在只能实现单选,全都不选实现不了,求

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");
                 }
            });
        });

热点排行