As shown below:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="ajaxselect.OnmouseTitle.WebForm1" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>WebForm1</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"> <script language="javascript"> function getvalue() { var b=document.all.rbtid.length var a=document.getElementById("rbtid").cells.length; //alert(b); result is 5 //alert(a); result is 4 //for(var i=0;i<b-1;i++) This works for(var i=0;i<a;i++) { var ss="rbtid_"+i; var aa=document.getElementById(ss).value; //if(eval('document.all.rbtid_'+i).checked==true) //This works for eval() function to convert the data string into js and run var bb=document.getElementById(ss); if(document.getElementById(ss).checked) //Note that checked cannot be written as Checked, otherwise it will not succeed { alert(aa); break; } } }Or use the second method:
//Get radiobuttonlist var vRbtid=document.getElementById("rbtid"); //Get all radio var vRbtidList= vRbtid.getElementsByTagName("INPUT"); for(var i = 0;i<vRbtidList.length;i++) { if(vRbtidList[i].checked) { var text =vRbtid.cells[i].innerText; var value=vRbtidList[i].value; alert("The text value of the selected item is "+text+", and the value is "+value); } }In this method, RadioButtonList is regarded as a table on the client side, and all its child radios are obtained through the getElementsByTagName("INPUT") method, then loop each radio, and then get the text value of radio through cells.
</script> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <FONT face="宋体"> <asp:radiobuttonlist id="rbtid" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" Width="216px" Height="176px" name="rbtid"> <asp:ListItem Value="0">0</asp:ListItem> <asp:ListItem Value="1" Selected>1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> </asp:radiobuttonlist><INPUT style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 256px" onclick="getvalue()" type="button" value="Button"></FONT> </form> </body></HTML>
The above two methods (recommended) for getting the radiobuttonlist selected value in Js are all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.