复选框按钮:
<input type="checkbox" id="check_all" name="check_all"
<c:if test="${on eq 'on'}">checked="checked"</c:if> />全选
<input type="checkbox" name="deptname_checkbox" value="${...}"/>
JS:
//全选及反选
$("#check_all").click(function(){
var flag = this.checked;
$("input[name=deptname_checkbox]").each(function(){
this.checked = !flag?false:true;
});
});
//选择复选框后若有操作时:(如查询)
<input type="submit" id="search_btn" value="查询" οnclick="search();"/>
function search(){
var dept_Ids = "";
$("input[name='deptname_checkbox']").each(function(){
if(this.checked==true){
dept_Ids+=this.value+",";
}
});
if(dept_Ids.length>0){
dept_Ids=dept_Ids.substring(0,dept_Ids.length-1);
}
document.getElementById('form1').action='..... +encodeURI(......); //中文传值乱码转换
document.getElementById('form1').submit();
}
//复选框回值
$("input[name=deptname_checkbox]").each(function(){
var deps = "${dept_Ids}";
if(deps.indexOf(this.value)!=-1) this.checked = true;
});
java后台:
String on = getRequest().getParameter("check_all");
getRequest().setAttribute("on", on);
String dept_Ids = getRequest().getParameter("dept_Ids");
getRequest().setAttribute("dept_Ids", dept_Ids);