如何使用 jQuery 从 RadioButtonList 获取值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20476487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get value from RadioButtonList using jQuery?
提问by CodeName-2956981
I need to find out what is the selected value of RadioButtonList:
我需要找出 RadioButtonList 的选定值是什么:
<div class="editor-field radio-button-list">
<%= Html.RadioButtonListForEnum("Type", Model.Type)%>
</div>
I tried to use: $("#Type").find(":checked").val()
but all I get is "undefined"... Any ideas?
我尝试使用:$("#Type").find(":checked").val()
但我得到的只是“未定义”......有什么想法吗?
回答by Adam Rackis
I'm not sure the id of Type is coming out how you think it is. Or maybe Type is a duplicate Id. In any event, I think this is what you want
我不确定 Type 的 id 是如何出现的。或者 Type 可能是重复的 Id。无论如何,我认为这就是你想要的
$(".editor-field.radio-button-list").find(":checked").val()
回答by Sambath Kumar S
It's working for server side control:
它适用于服务器端控制:
$("#<%=ControlID.ClientID%>").find(":checked").val();
回答by iIrfan
$(".editor-field.radio-button-list:checked").val()
回答by rotem
var val = $('#<%= ControlID.ClientID %> input:checked').val();
var val = $('#<%= ControlID.ClientID %> input:checked').val();