复选框只能选中一个

//html代码:
<input id="1" type="checkbox" class="dept" onclick="check(this)" />
      <input id="2" type="checkbox" class="dept" onclick="check(this)" />
         <input id="3" type="checkbox" class="dept" onclick="check(this)" />
 
//js:
  //只能选择一个部门
        function check(obj) {
            $('.dept').attr('checked', false);//清空所有复选框
            $(obj).attr('checked', true);//给当前对象赋值
        }

你可能感兴趣的:(复选框只能选中一个)