JS获取RadioButtonList选中的Valuet和Text

ASPX:
程序代码 程序代码

<asp:RadioButtonList ID="rblTest" runat="server"
  RepeatDirection="Horizontal" RepeatLayout="Flow">
    <asp:ListItem Value="1" Text="第一个"></asp:ListItem>
    <asp:ListItem Value="2" Text="第二个"></asp:ListItem>
    <asp:ListItem Value="3" Text="第三个"></asp:ListItem>
    <asp:ListItem Value="4" Text="第四个"></asp:ListItem>
    <asp:ListItem Value="5" Text="第五个"></asp:ListItem>
</asp:RadioButtonList>

<input id="ibTest" type="button" value="button" onclick="GetRadioButtonList();" />


脚本代码:
程序代码 程序代码

function GetRadioButtonList()
{
var rblTests=document.getElementsByName("rblTest");
var rblValue;
var rblText;
for(var i=0;i<rblTests.length;i++)
{
   if(rblTests[i].checked)
   {
     rblValue=rblTests[i].value;
     rblText=rblTests[i].nextSibling.childNodes[0].nodeValue;
     break;
   }
}

alert(rblValue);
alert(rblText);
}


编辑器里手工编写,没测试过。


评论: 0 | 引用: 0 | 查看次数: 6502
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭