JS获取RadioButtonList选中的Valuet和Text
作者:岸上的鱼 日期:2009-04-16
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);
}
编辑器里手工编写,没测试过。

<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
发表评论