簡體   English   中英

如何檢查是否選擇了在數據網格內部動態創建的單選按鈕?

[英]How to check whether a radio button is selected which is created inside a data grid dynamically?

我有一個在運行時填充一些值的數據網格。 前兩列用於單選按鈕,第一列包含“是”,第二列包含“否”。 數據網格中有n行。 如果選擇了“是”,則將出現一個文本框。 我該如何實現?

我嘗試使用

$(".class").each(function () {
    if ($(this).checked) {
        textbox.visible = true;
    }
});

但是$(this).checked返回false

您可以嘗試使用prop ,它會根據是否檢查天氣返回true / false。

$(".class").each(function() {
   if( $(this).prop('checked') ) 
   {  
      textbox.visible = true; 
   }
});

以下代碼段將回答您的問題

 $('.class').click(function(){ $(".class").each(function() { if($(this).is(':checked') && $(this).val()=='yes' ) { console.log($(this).prop('name') + ' checked'); } }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table > <tr> <td>Yes</td><td>No</td> </tr> <tr> <td><input name='question1' value='yes' type='radio' class='class'/></td><td><input name='question1' type='radio' class='class'/></td> </tr> <tr> <td><input name='question2' value='yes' type='radio' class='class'/></td><td><input name='question2' type='radio' class='class'/></td> </tr> <tr> <td><input name='question3' value='yes' type='radio' class='class'/></td><td><input name='question3' type='radio' class='class'/></td> </tr> </table> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM