以下程序运行后,产生一系列单选按钮,但是不同组之间的单选按钮也有影响了,就是所有按钮只能选择一个了,而我却是定义了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>

解决方案 »

  1.   

    radio本来就是只选择一个啊要相每组选择一个,适当加个table试试
      

  2.   

    放到不同的form里面就好了
    <%@ 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 >
      

  3.   

    <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 > 
    上面代码是一块字符,它实际上并不会改了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 > 
      

  4.   

    嗯。可以了,非常感谢。那再问一下,我明明已经定义了5组不同的按钮了啊,名字是不同的,是不是在同一FORM下的按钮都是算同一组的?哪怕名字不同也没用?
      

  5.   

    你的想法是把它分成五组,其实并没有分成,所有单选框名均是selection
    <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下的按钮不都算是一组,只要他们名字不同就是不同的组
      

  6.   

    做完后可以右键点击页面查看源码,就可以看到自己写的东西的最终生成的html代码,可以通过看这些东西知道自己为什么错了