日期:2014-05-18  浏览次数:20756 次

JSP复选框的全选是如何实现的哪
如何做?

------解决方案--------------------
JS循环
------解决方案--------------------
function selectAll() {
for(i = 0;i < document.delectform.elements.length;i++)
{
if(document.delectform.elements[i].type!= "checkbox ") continue;

document.delectform.elements[i].checked = true;

}
return false;
}

------解决方案--------------------
mark
------解决方案--------------------
------------------------------HTML-------------------------
......
<form name= "form2 " method= "post " action= " "〉
<%
int num=1;
for(num=1;num <=9;num++)
{
%>
<input type= "checkbox " name= "select <%=num%> " value= "1 "> 选择 <%=num%>
<%
}
%>
<input name= "button " type=button onClick= "checkAll() " value= "全部选中 "> &nbsp;&nbsp;
<input type=button value= "全部不选 " onClick= "uncheckAll() "> &nbsp;&nbsp;
<input type=button value= "选择转换 " onClick= "switchAll() "> &nbsp;&nbsp;
<input type= "submit " name= "Submit " value= "提交 "> &nbsp;&nbsp;
</from>
.....
-----------------------------------------
------------------------------js---------------------------------------------

<SCRIPT LANGUAGE= "JavaScript ">

<!-- Begin
function checkAll() {
for (var j = 1; j <= <%=num%> ; j++) {
box = eval( "document.form2.select " + j);
if (box.checked == false) box.checked = true;
}
}

function uncheckAll() {
for (var j = 1; j <= <%=num%> ; j++) {
box = eval( "document.form2.select " + j);
if (box.checked == true) box.checked = false;
}
}

function switchAll() {
for (var j = 1; j <= <%=num%> ; j++) {
box = eval( "document.form2.select " + j);
box.checked = !box.checked;
}
}
// End -->
</script>
------------------------------------------
------解决方案--------------------
JS里可以加JSP代码,但是首先运行JSP代码