通过javascript

时间:2017-02-13 19:50:51

标签: javascript asp.net

我谷歌搜索并搜索到通过JavaScript获取asp radiobutton值的值,但我一直未定义。我几乎找到了获取rb值的所有方法但确定为什么我得到了未定义。任何帮助表示赞赏。

单击对话框窗口“确定”按钮时,将调用clientfunction()。

这是我的代码。

                                                   
    <div style="width: 480px;">
<MyUserControl:FormItem ID="FormItem1" runat="server" Label="Outcome" IsRequired="true">
                            <Content>
                                <div>
                                    <asp:RadioButton ID="rbThisButton" GroupName="outcome" Text="This radio button" runat="server" Checked="<%# model.thisbutton %>" />
                                </div>

                            </Content>
                        </MyUserControl:FormItem>








 <script type="text/javascript">
     function clientFunction() {

         debugger;
         $('select[id$=rbThisButton]').each(function () {
             var val = this.value;
             if (val == 'All') { flag = true; }
         });

         var test = $('#<%=rbThisButton.ClientID %> input[type=radio]:checked').val();

         var selectedVal = $("[id$='rbThisButton']").find(":checked").val();


         var selectedvalue = $('#<%= rbThisButton.ClientID %> input:checked').val()


         debugger;
         var rates = document.getElementById('rbThisButton'); 

     }   
    </script>
</asp:Content>

1 个答案:

答案 0 :(得分:0)

如果您想知道是否选中了单选按钮,您只需执行以下操作:

var isChecked = $('#<%=rbThisButton.ClientID %>').is(":checked");

要打破你的尝试无效的原因:

$('select[id$=rbThisButton]')
//This is looking for a SELECT (DropDownList), not an input

$('#<%=rbThisButton.ClientID %> input[type=radio]:checked')
$("[id$='rbThisButton']").find(":checked")
$('#<%= rbThisButton.ClientID %> input:checked')
//Both a space in a selector and the .find() function are looking for CHILDREN
//so you're not finding anything with these - your radio button has no children