vik*_*kas 3 javascript asp.net
我有一个radibutton列表.
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" RepeatLayout="flow" >
<asp:ListItem Selected="True" Text ="Yes" Value="0"></asp:ListItem>
<asp:ListItem Text ="No" Value="1"></asp:ListItem>
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)
为了从无线电列表中获取值,我有一个功能:
function getvalueofradiolist() {
var radiolist = document.getElementById('<%= RadioButtonList1.ClientID %>');
var rblName = radiolist.name;
var radio = document.getElementsByName(rblName);
for (var x = 0; x < radio.length; x++) {
if (radio[x].checked) {
alert("Selected item Value " + radio[x].value);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但它返回undefined.
我写错了吗?
我点击按钮调用此功能.
建议我如果我可以在Javascript的帮助下使用代码来做到这一点.
Afs*_*hin 13
<form runat="server">
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal" RepeatLayout="flow" >
<asp:ListItem Selected="True" Text ="Yes" Value="0"></asp:ListItem>
<asp:ListItem Text ="No" Value="1"></asp:ListItem>
</asp:RadioButtonList> </form>
<p id="button" onclick="getvalue()">click me</p>
<script type="text/javascript">
function getvalue(){
alert($('#<%=RadioButtonList1.ClientID %> input[type=radio]:checked').val());
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40510 次 |
| 最近记录: |