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);//给当前对象赋值
}
做个笔记,记忆力不行哦!