循环里同名checkbox如何限定选取个数
<%
i=0
Do While Not Rs.Eof
i=i+1
%>
<TABLE>
<TBODY>
<tr>
<td height= "30 "> <input type= "hidden " name= "tid " value= " <%=rs( "id ")%> " > <%=i%> 、 <B> <FONT class=title1> <%=rs( "title ")%> </FONT> </B> </td>
</tr>
<TR>
<TD> <TABLE>
<TBODY>
<% sql2= "select * from yh "
Set Rs2=Server.CreateObject( "ADODB.RecordSet ")
Rs2.Open sql2,Conn,1,1
%>
<tr>
<TD vAlign=bottom>
<INPUT type= " <%=lx%> " name=uid onClick= "doCheck(this) " value= <%=rs2( "uname ")%> >
<LABEL> <%=rs2( "uname ")%> </LABEL> </TD>
</tr>
<%
Rs2.MoveNext
Loop%>
</TBODY>
<% rs2.close
set rs2=nothing
%>
</TABLE> </TD>
</TR>
</TBODY>
</TABLE>
<%
Rs.MoveNext
Loop%>
------解决方案-------------------- <script>
function chk(obj1){
var obj = document.forms[0];
var max = 5;
var j = 0;
if (obj.s.length){
for (i = 0; i < obj.s.length; i++){
if (obj.s[i].checked) j++;
if (j > max){
alert( "对不起,最大选取 " + max + "。 ");
obj1.checked = false;
break;
}
}
}
}
</script>
<form>
<input type= "checkbox " name= "s " value= "1 " onclick= "chk(this); " />
<input type= "checkbox " name= "s " value= "2 " onclick= "chk(this); " />
<input type= "checkbox " name= "s " value= "3 " onclick= "chk(this); " />
<input type= "checkbox " name= "s " value= "4 " onclick= "chk(this); " />
<input type= "checkbox " name= "s &