有N组radio列表,第一组名为radio1
第二组radio2
第三组radio3
第n组radio..n
使用js 如何能得出我每一组把选的值 啊
请高手指点

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>js测试</title><script src="jquery-1.3.2.js"></script>
    <script>
    $(document).ready(function(){
    var i = 0;
        $("input[type=radio]").each(function(){
        if($(this).is(":checked")){
       i++;
    }
    });
    alert("共"+i+"个被选中")
    });
    </script>
    </head>
    <body>     <input class="test" type="radio" checked="checked"/>
         <input class="test" type="radio"/>
         <input class="test" type="radio" checked="checked"/>
         <input class="test" type="radio"/>
         <input class="test" type="radio"/></body>
    </html>
      

  2.   


    function getRads(groupname){
     var radlist = document.getElementsByName(groupname);
     for(var i =0;i<radlist.length;i++)
     {
       alert(radlist[i].value);
     }
    } <input type = 'radio' name = "radio1" value = "1"/>第一个<br/>
     <input type = 'radio' name = "radio1" value = "2"/>第二个<br/><br/>
     <input type = 'radio' name = "radio2" value = "2-1"/>第一个<br/>
     <input type = 'radio' name = "radio2" value = "2-2"/>第二个<br/>
     <input type = "button" value = "获取值" onclick = "getRads('radio1');"/>
      

  3.   


    function getRads(){
     var radlist = document.getElementsByTagName("input");
     for(var i =0;i<radlist.length;i++)
     {
       if(radlist[i].type=="radio" && redlist[i].checked)
       alert(radlist[i].value);
     }
    }<input type = "button" value = "获取值" onclick = "getRads();"/>