Page_load里RadioButtonList1绑定后,添加下面代码
foreach (ListItem item in RadioButtonList1.Items)
        {
            item.Attributes.Add("onclick", "getVal('" + item.Value + "','" + item.Text + "')");
        }
前台获的
function getVal(itemValue,itemText){
 alert(itemValue);//获得选择的value
 alert(itemText);}

解决方案 »

  1.   

    1楼 ,谢谢 ,但本身页面已经做完 ,需要添加个功能 ,能不能直接在我的onclick方法中取得我需要的text和value ,而不是c#中添加完了再取 ?要是没别的方法 ,只能那么改了 ,那页面改动就太多了 。因为不少页面 ,不少RadioButtonList 控件呀 。
      

  2.   

    <input type="button" value="获得radio text和value" onclick="getSelectRadio()" />
     <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            </asp:RadioButtonList><script language="javascript">
        function getSelectRadio()
        {
            var o = {};
            var radiolist = document.getElementById("RadioButtonList1");
            for(var i=0;i<radiolist.rows.length;i++){
                var radio = radiolist.rows[0].cells[0].childNodes[0];
                if(radio.checked){
                    o.value = radio.value;
                    o.text = radiolist.rows[0].cells[0].childNodes[1].innerText;
                    break;
                }
            }
            
            alert(o.value);
            alert(o.text);
            
        }
        </script>
      

  3.   

    如果你用到母板页这里改成ClientID 
    var radiolist = document.getElementById("<%=RadioButtonList1.ClientID %>");
      

  4.   

     当RadioButtonList在页面生成后 ,名字会改变 ,页面文件的源码变成这样:<input id="RadioButtonList1_0" type="radio" name="RadioButtonList" value="1" />
    <label for="RadioButtonList_0">name1</label>
    <input id="RadioButtonList_1" type="radio" name="RadioButtonList" value="2" />
    <label for="RadioButtonList_1">name2</label>
    <input id="RadioButtonList_2" type="radio" name="RadioButtonList" value="3" />
    <label for="RadioButtonList_2">name3</label>
    <input id="RadioButtonList_3" type="radio" name="RadioButtonList" value="4" />
    <label for="RadioButtonList_3">name4</label> var radiolist = document.getElementById("RadioButtonList1") ;radiolist 就等于null 了,怎么解决呢?
      

  5.   

    var radiolist = document.getElementById(" <%=RadioButtonList1.ClientID %>");
    RadioButtonList1是<asp:RadioButtonList的ID,不是里面每个radio的ID
      

  6.   


    alert(" <%=RadioButtonList1.ClientID %>“) 时,正常显示RadioButtonList1 ;
    但var radiolist = document.getElementById(" <%=RadioButtonList1.ClientID %>"); 
    alert(radiolist) 时,就是null     。麻烦CutBug了 。
      

  7.   

    var radiolist = document.getElementById(" <%=RadioButtonList1.ClientID %>"); 
    你页面没有载入,alert当然是null
      

  8.   

    <asp:RadioButtonList ID="rblGenerationScene" RepeatDirection="Horizontal"
                                         RepeatLayout="Flow" runat="server" RepeatColumns="3" onclick="setTextBox()"></asp:RadioButtonList><script language="javascript">function setTextBox()
      {  
           alert('<%=rblGenerationScene.ClientID%>');
            var radiolist = document.getElementById('<%=rblGenerationScene.ClientID%>');
            alert(radiolist);
    }</script>
      

  9.   

    我没有对radiobuttonlist进行数据绑定,直接内置了几个数据,应该不相干!点击每一项,可以得到。楼主主要能在客户端,获取到该Radiobuttonlist的客户端ID,这个方法就是通用的了。直接传入Radiobuttonlist的客户端ID,就能用了!<asp:radiobuttonlist ID="Radiobuttonlist1" runat="server" 
            RepeatDirection="Horizontal">
        <asp:ListItem>111111</asp:ListItem>
        <asp:ListItem>2222</asp:ListItem>
        <asp:ListItem>33333</asp:ListItem>
        <asp:ListItem>4444</asp:ListItem>
        <asp:ListItem>555555</asp:ListItem>
        <asp:ListItem>666666666</asp:ListItem>
        </asp:radiobuttonlist>
       
        <script type="text/javascript">
            var radioButtonListArray = document.getElementsByName("Radiobuttonlist1");
            for (var i = 0; i < radioButtonListArray.length; i++) {
                if ((radioButtonListArray[i].type != "undefined") && (radioButtonListArray[i].type == "radio")) {
                    radioButtonListArray[i].onclick = function() {
                             alert("value值:" + this.value + "\r\n" + "text值:" + this.nextSibling.innerHTML);
                     }
                }
            }
        </script>