check是在ajax响应中检查的无线电元素

时间:2014-03-31 12:07:44

标签: javascript jquery ajax response

我有一个包含两个无线电元素的ajax响应。我想检查是否检查了无线电元素。

我使用下面的代码检查无线电状态但无法正常工作。

  $('#input[type=radio]').each(function(){
 alert($(this).attr('checked'));
});

因为我知道由于ajax响应而无法正常工作。但是如何解雇js代码甚至在ajax resoponse中检查。

任何帮助都会非常感激。

4 个答案:

答案 0 :(得分:1)

试试这个:

$(document).find('input[type="radio"]').each(function(){
   if($(this).is(':checked')){
      //your code
   }
});

答案 1 :(得分:0)

试试这个

$('#input[type=radio]').each(function(){
 if($(this).is(':checked')){

 }
});

答案 2 :(得分:0)

使用prop

  $('input[type=radio]').each(function(){
 alert($(this).prop('checked'));
});

和#input仅在收音机有id =“input”时才输入。如果你想检查所有收音机,可能只是

input[type=radio] 

作为例子

答案 3 :(得分:0)

您的问题是您的选择器,其中包含#的ID:

$('#input[type=radio]')
//-^------------------------# is used to select an id not the tags

试试这个:

$('input[type="radio"]').each(function(){
    alert(this.checked); // returns "true" if checked/ "false" if not checked
});