RadioButtonList被编译以后成了数个RadioButtonList1_1(2,3....)之类的怪胎,有没有办法用js实现获得RadioButtonList的index的值?我的意思是能不能在客户端通过分析RadioButtonList1_1的名称及状态来得知那个被选中?

解决方案 »

  1.   

    应该可以,但我没做过:((但是找过selected和input)可以找名字规律看看:)
      

  2.   

    是啊,怎么做啊?关键是我想知道如何得知如何判定客户端radiobutton的状态啊?
      

  3.   

    如何通过js判定radiobutton的状态啊?
      

  4.   

    OK,给你写了一段代码,希望对你有帮助:
    -------------------------
    在HTML中:
    -------------------------
    <form id="Form1" method="post" runat="server">
    <asp:RadioButtonList id="RadioButtonList1" runat="server">
    <asp:ListItem Value="item1">item1</asp:ListItem>
    <asp:ListItem Value="item2">item2</asp:ListItem>
    <asp:ListItem Value="item3">item3</asp:ListItem>
    </asp:RadioButtonList><INPUT type="button" value="Button" onclick="chk()">
    </form>
    ------------------
    在<head></head>之间加上以下这段函数:
    ------------------
    function chk()
    {
      var ary=document.all.tags("input");
      for(var i=0;i<ary.length;i++)
      {
        if(ary[i].type=="radio")
        {
          if(ary[i].checked==true)
          {
            alert(ary[i].value);
          }
        }
      }
    }
    </script>
      

  5.   

    能不能跨掉button这个中间部分而直接选取时就触发一个事件而不刷服务器呢?
      

  6.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>Temp</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body>
    <form name="Form1" method="post" action="temp.aspx" id="Form1">
    <input type="hidden" name="__VIEWSTATE" value="dDwtMTc2MTIzNDA0Njs7Pg==" /> <FONT face="宋体">&nbsp;&nbsp;&nbsp; </FONT>&nbsp;
    <table id="RadioButtonList1" border="0">
    <tr>
    <td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="radio1" /><label for="RadioButtonList1_0">radio1</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="radio2" /><label for="RadioButtonList1_1">radio2</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="radio3" /><label for="RadioButtonList1_2">radio3</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_3" type="radio" name="RadioButtonList1" value="radio4" /><label for="RadioButtonList1_3">radio4</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_4" type="radio" name="RadioButtonList1" value="radio5" /><label for="RadioButtonList1_4">radio5</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_5" type="radio" name="RadioButtonList1" value="radio6" /><label for="RadioButtonList1_5">radio6</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_6" type="radio" name="RadioButtonList1" value="radio7" /><label for="RadioButtonList1_6">radio7</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_7" type="radio" name="RadioButtonList1" value="radio8" /><label for="RadioButtonList1_7">radio8</label></td>
    </tr><tr>
    <td><input id="RadioButtonList1_8" type="radio" name="RadioButtonList1" value="radio9" /><label for="RadioButtonList1_8">radio9</label></td>
    </tr>
    </table></form>
    <script>
    function getIndex(obj)
    {
    obj = document.getElementById("RadioButtonList1");
    var n = -1;
    var txt = null;
    for(i=0;i<obj.rows.length;i++)
    {
    var r = document.getElementById(obj.id + "_" + i);
    if(r.checked)
    {
    n = i;
    txt = r.value;
    }
    }
    if(n!=-1)
    alert(txt + " 被选中了!");

    }
    </script>
    <INPUT type="button" value="Button" onclick="getIndex('RadioButtonList1');">
    </body>
    </HTML>
      

  7.   

    function getckindex(RadioButtonListID)
    {
      var i = 1;
      
      while(document.all[RadioButtonListID+'_'+i] != null)
    {
       if(document.all[RadioButtonListID+'_'+i].checked == true)
            return i;
       i++;
    }
    return 0;
    }use like this :var ckindex = getckindex("RadioButtonList1");