html
<input type ="radio" name="aa"  id ="rod1"/>
<input type ="radio" name="aa"  id ="rod2"/>
<input type ="radio" name="aa"  id ="rod3"/>请问如何用js获取选中的id,并传给后台  

解决方案 »

  1.   


    document.body.onclick = function(){
         var els = document.getElementsByName("aa");
      for (var i = els.length; i--;){
                    var el = els[i]
      if (el.checked){
      alert(el.getAttribute("id"))
      }
      }
    }
      

  2.   

    一般传value值如:
    <input type ="radio" name="aa" id ="rod1" value="rod1"/>
    <input type ="radio" name="aa" id ="rod2" value="rod1"/>
    <input type ="radio" name="aa" id ="rod3" value="rod1"/>
    function GetSelectedVal()
    {
       var rds=document.getElementsByName("aa");
       var rdVal;
       for(var i=0;i<rds.length;i++)
       {
         if(rds.item(i).checked){
             rdVal=rds.item(i).getAttribute("value"); 
             alert(rdVal);
             break;
          }
         else{
          continue;
          }
       }
    }
      

  3.   

    <input type ="radio" name="aa" id ="rod1"  onclick="fn(this);"/>1
    <input type ="radio" name="aa" id ="rod2"  onclick="fn(this);"/>2
    <input type ="radio" name="aa" id ="rod3"  onclick="fn(this);"/>3<script>
    function fn(_self){
    if(_self.checked) alert(_self.id);
    }
    </script>
      

  4.   


    <input type ="radio" name="aa" id ="rod1"/>
    <input type ="radio" name="aa" id ="rod2"/>
    <input type ="radio" name="aa" id ="rod3"/>
    <input type="hidden" name="radioValue" id="radioValue">
    <input type="submit" onclick="fn()">加一个隐藏的input,将被选择的radio中的ID值赋给它,然后在后台取radioValue的值
    function fn(){
         var els = document.getElementsByName("aa"),
             hEl = document.getElementById("radioValue");
         for (var i = els.length; i--;){
             var el = els[i];
             if (el.checked){
                 hEl.value = el.getAttribute("id");
                 break;
             }
         }
    }
      

  5.   

    你把id放在隐藏域,或者放在url后用参数传到后台
    后台用request.getParameter()取就行
      

  6.   

    在每行加一个onclick函数,选中(点击)的时候,给他赋一个属性,取消的时候去掉该属性,然后提交的时候循环input。有属性的表示选中的。
      

  7.   

    .net好像是request.queryString(""),lz点完试试吧,不过.net的url传值与form传值后,取值是不一样的,那个只适用于url的,form的好像要request.forms[""];lz试试吧
      

  8.   

    用case语句判断一下哪一个radio是checked,就取它的ID做为提交的值就行了