2017-02-13 59 views
0

我GOOGLE和搜索全部通過JavaScript獲取asp單選按鈕值的值,但我一直未定義。我尋找幾乎所有的方式來獲得rb值,但肯定爲什麼我不明確。任何幫助表示讚賞。獲取asp單選按鈕值通過JavaScript

當單擊對話框窗口確定按鈕時調用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> 
+0

什麼時候調用'clientFunction'? –

+0

ClientFunction在點擊'OK'按鈕時被調用。 – John

+0

'asp:radiobutton'生成一個'',所以你爲什麼要嘗試一個選擇器:'select [id $ = rbThisButton]'而不是'input [type = radio] [id * = rbThisButton ]' –

回答

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