各位大哥:
   小弟有一问题等待你们救命啊,我在页面上循环多组radio框,这该怎么做啊,现在的情况是循环出来的记录,比如10条,每条上有2个选项,是和否,这10组radio框只能选一组。怎样才能让每组都能选择呢?谢谢!不胜感激,就这点分都给了!
   

解决方案 »

  1.   

    呵呵,为何不用checkbox,这样不就可以了,提交后取到的选中的checkbox中的值是一个数组,
      

  2.   

    把一个“是”“否”作一组radio,一个组里是只能选"是"或则"否"
    有几个要选择的就作几个组吧
    这样每个组都能选择了
      

  3.   

    我的记录是不固定的,可能这个是10条,下一个就变成5条了。
    checkbox比如我有10条记录,5条打勾,那么actionform获取的数组数是5,而没有打勾的那五条我获取不到啊。
      

  4.   

    不是没法回答
    不知道你怎么循环的(js,还是struts标签,还是jstl等等)
    咋回答?
      

  5.   

    让同一组的radio name相同
    例如:
    <input type="radio" name="r1"/>
    <input type="radio" name="r1"/>
    <br>
    <input type="radio" name="r2"/>
    <input type="radio" name="r2"/>
    <br>
    <input type="radio" name="r3"/>
    <input type="radio" name="r3"/>
      

  6.   

    我大致明白你的意思了,你的单选按钮个数不确定,那么你每组单选按钮的name可以设置成不一样吗?
      

  7.   

    你必须把每组的name设置成不一样的,在通过JS可以取到所有的单选按钮,将值可以通过隐藏表单域提交过去
      

  8.   

    NAME需要不同,可以在name中加入每行行数
      

  9.   

    几天前就帮你写了一下
    <html>
    <head>
    <title>radio</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript">
    function check(){
    var radios=document.getElementsByTagName("input");
    for(var i=0;i<radios.length;i++){
    if(radios[i].type=="radio"){
    if(radios[i].checked){
    alert(radios[i].name+"\t"+radios[i].value);
    }
    }
    }

    }
    </script>
    </head> <body>
    <input type="radio" name="radio1" value="true">是
    <input type="radio" name="radio1" value="false">否
    <br>
    <input type="radio" name="radio2" value="true">是
    <input type="radio" name="radio2" value="false">否
    <br>
    <input type="radio" name="radio3" value="true">是
    <input type="radio" name="radio3" value="false">否
    <br>
    <input type="radio" name="radio4" value="true">是
    <input type="radio" name="radio4" value="false">否
    <br>
    <input type="radio" name="radio5" value="true">是
    <input type="radio" name="radio5" value="false">否
    <br>
    <input type="button" value="submit" onclick="check();">
    </body>
    </html>