62,267
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script>
function GetRblValue() {
var ipts = document.getElementById("RadioButtonList1").getElementsByTagName("input");
var value;
for (i = 0; i < ipts.length; i++) {
if (ipts[i].checked) {
value = ipts[i].value;
break;
}
}
alert(value);
//return value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="1">a</asp:ListItem>
<asp:ListItem Value="2">b</asp:ListItem>
<asp:ListItem Value="3">c</asp:ListItem>
<asp:ListItem Value="4">d</asp:ListItem>
</asp:RadioButtonList>
<input type="button" value="得到radiobuttonlist的值" onclick='GetRblValue()' />
</div>
</form>
</body>
</html>
js取ASP.NET服务器控件RadioButtonList选中的值
<script type="text/javascript">
//取得RadioButtonList客户端id 如服务器端控件RadioButtonList的服务器端ID为:rblTest
var radioButtonListClientID="<%= rblTest.ClientID %>"
//根据RadioButtonList控件的客户端id取被选中的值
//oId 为控件的客户端id
//返回null时为没有选中
function GetRadioButtonListSelectValue(oId) {
var returnValue=null;
var oRadioButtonList=document.getElementById(oId);
var oRadioButtonLists=oRadioButtonList.getElementsByTagName('input');
for(var i=0;i<oRadioButtonLists.length;i++) {
if(oRadioButtonLists[i].type == "radio") {
if(oRadioButtonLists[i].checked) {
returnValue = oRadioButtonLists[i].value;
break;
}
}
}
return returnValue;
}
</script>