admin管理员组文章数量:1331943
<asp:RadioButtonList ID="rbl" runat="server" onMouseUp="Myf()">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
function Myf() {
var list = document.getElementById("<%=rbl.ClientID %>");
var inputs = list.getElementsByTagName("input");
var selected;
for (var i = 0; i < inputs.length; i++) {
alert(inputs[i].innerHTML);
}
}
I'm getting the value of Radiobuttonlist. How to get the Text of the Radiobuttonlist?
<asp:RadioButtonList ID="rbl" runat="server" onMouseUp="Myf()">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
function Myf() {
var list = document.getElementById("<%=rbl.ClientID %>");
var inputs = list.getElementsByTagName("input");
var selected;
for (var i = 0; i < inputs.length; i++) {
alert(inputs[i].innerHTML);
}
}
I'm getting the value of Radiobuttonlist. How to get the Text of the Radiobuttonlist?
Share Improve this question edited Jun 28, 2013 at 12:13 Pearl asked Jun 28, 2013 at 12:06 PearlPearl 9,4458 gold badges45 silver badges60 bronze badges 2- 1 Can you provide this code in Jsfiddle – S. S. Rawat Commented Jun 28, 2013 at 12:09
- Radiobuttons do not have text. Text is in label element. – YD1m Commented Jun 28, 2013 at 12:11
5 Answers
Reset to default 6First of all the radio buttons do not have text in your code
Second, if you look at the source of the resulting html page, you can see that the radio buttons have labels that store the text.
So you can look for label
instead of input
in your function and it will get the text
function Myf() {
var list = document.getElementById("<%=rbl.ClientID %>");
var inputs = list.getElementsByTagName("label");
var selected;
for (var i = 0; i < inputs.length; i++) {
alert(inputs[i].innerHTML);
}
}
Use the getAttribute() method.
element.getAttribute("Text");
More info on: https://developer.mozilla/en-US/docs/Web/API/element.getAttribute?redirectlocale=en-US&redirectslug=DOM%2Felement.getAttribute
To get text you have to put "label" instead of "input" in getelement.
try like this:
var inputs = list.getElementsByTagName("label");
<asp:RadioButtonList ID="rbl" runat="server">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList>
$(document).ready(function () {
$('[id*="rdl"],[type="radio"]').change(function () {
if ($(this).is(':checked'))
console.log($(this).next('label').html());
});
});
try this
function Myf() {
$("#<%=rbl.ClientID %>").find('input').each(function () {
var this_input = $(this);
alert($("#<%=rbl.ClientID %>").find('label[for="' + this_input.attr('id') + '"]').text());
})
}
本文标签: cHow to get the Text of the RadiobuttonlistStack Overflow
版权声明:本文标题:c# - How to get the Text of the Radiobuttonlist? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742236255a2438134.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论