$(function(){
$(':checkbox[type="checkbox"]').each(function(){
$(this).click(function(){
if($(this).attr('checked')){
$(':checkbox[type="checkbox"]').removeAttr('checked');
$(this).attr('checked','checked');
/* alert(this.id); */ /*如果不注释,在页面上会有消息框弹出*/
}
});
});
});
<div class="control-group">
<label class="control-label">用户角色:</label>
<div class="controls">
<form:checkboxes path="roleIdList" items="${allRoles}" name="chk" itemLabel="name" itemValue="id" htmlEscape="false" class="required"/>
<span class="help-inline"><font color="red">*</font> </span>
</div>
</div>
方法来自CSDN某位作者,时间长了忘记是谁了。