以下程序运行后,产生一系列单选按钮,但是不同组之间的单选按钮也有影响了,就是所有按钮只能选择一个了,而我却是定义了5组(体现在注释语句中),请教各位,谢谢。<%@ page contentType = "text/html;charset=GB2312" %>
<HTML>
<HEAD><TITLE>test</TITLE></TITLE>
<BODY>
<%!
String selection;
int index = 1;
%>
<%
for (int i = 1; i <= 25; i++)
{
if ((i-1) % 5 == 0)
{
out.print("题目<BR>");
}
else
{
selection = "" + index; // 换一组单选按钮
%>
<INPUT type = "radio" name = selection value = "A"></INPUT> A<BR>
<INPUT type = "radio" name = selection value = "B"></INPUT> B<BR>
<INPUT type = "radio" name = selection value = "C"></INPUT> C<BR>
<INPUT type = "radio" name = selection value = "D"></INPUT> D<BR>
<%
i += 3;
index++;
}
}
%>
</BODY>
</HTML>
<HTML>
<HEAD><TITLE>test</TITLE></TITLE>
<BODY>
<%!
String selection;
int index = 1;
%>
<%
for (int i = 1; i <= 25; i++)
{
if ((i-1) % 5 == 0)
{
out.print("题目<BR>");
}
else
{
selection = "" + index; // 换一组单选按钮
%>
<INPUT type = "radio" name = selection value = "A"></INPUT> A<BR>
<INPUT type = "radio" name = selection value = "B"></INPUT> B<BR>
<INPUT type = "radio" name = selection value = "C"></INPUT> C<BR>
<INPUT type = "radio" name = selection value = "D"></INPUT> D<BR>
<%
i += 3;
index++;
}
}
%>
</BODY>
</HTML>
<%@ page contentType = "text/html;charset=GB2312" % >
<HTML >
<HEAD > <TITLE >test </TITLE > </TITLE >
<BODY >
<%!
String selection;
int index = 1;
% >
<%
for (int i = 1; i <= 25; i++)
{
if ((i-1) % 5 == 0)
{
out.print("题目 <BR >");
}
else
{
selection = "" + index; // 换一组单选按钮
% >
<form name="<%=i%>">
<INPUT type = "radio" name = selection value = "A" > </INPUT > A <BR >
<INPUT type = "radio" name = selection value = "B" > </INPUT > B <BR >
<INPUT type = "radio" name = selection value = "C" > </INPUT > C <BR >
<INPUT type = "radio" name = selection value = "D" > </INPUT > D <BR >
</form>
<%
i += 3;
index++;
}
}
% >
</BODY >
</HTML >
<INPUT type = "radio" name = selection value = "B" > </INPUT > B <BR >
<INPUT type = "radio" name = selection value = "C" > </INPUT > C <BR >
<INPUT type = "radio" name = selection value = "D" > </INPUT > D <BR >
上面代码是一块字符,它实际上并不会改了name=selection的值,也就是说这些radio是一组的,都是selction组,
你这样写一下应该就好了,
<INPUT type = "radio" name = <%=selection%> value = "A" > </INPUT > A <BR >
<INPUT type = "radio" name = <%=selection%> value = "B" > </INPUT > B <BR >
<INPUT type = "radio" name = <%=selection%> value = "C" > </INPUT > C <BR >
<INPUT type = "radio" name = <%=selection%> value = "D" > </INPUT > D <BR >
<INPUT type = "radio" name = selection value = "A" > </INPUT > A <BR >
<INPUT type = "radio" name = selection value = "B" > </INPUT > B <BR >
<INPUT type = "radio" name = selection value = "C" > </INPUT > C <BR >
<INPUT type = "radio" name = selection value = "D" > </INPUT > D <BR >
应该改为
<INPUT type = "radio" name = <%=selection %> value = "A" > </INPUT > A <BR >
<INPUT type = "radio" name = <%=selection %> value = "B" > </INPUT > B <BR >
<INPUT type = "radio" name = <%=selection %> value = "C" > </INPUT > C <BR >
<INPUT type = "radio" name = <%=selection %> value = "D" > </INPUT > D <BR >
<INPUT type = "radio" name = <%=selection %> value = "E" > </INPUT > E <BR >
在同一form下的按钮不都算是一组,只要他们名字不同就是不同的组