我有一组单选按钮,我想取消后AJAX表单提交使用jQuery。我有以下功能:

function clearForm(){
  $('#frm input[type="text"]').each(function(){
      $(this).val("");  
  });
  $('#frm input[type="radio":checked]').each(function(){
      $(this).checked = false;  
  });
 }

在这个函数的帮助下,我可以清除文本框中的值,但我不能清除单选按钮的值。

顺便说一下,我还尝试了$(this).val("");但这并没有起作用。


当前回答

使用这个

$("input[name='nameOfYourRadioButton']").attr("checked", false);

其他回答

(纯js)

this.checked = false;

或(jQuery)

$(this).prop('checked', false);
// Note that the pre-jQuery 1.6 idiom was
// $(this).attr('checked', false);

请参阅jQuery prop()帮助页面,了解attr()和prop()之间的区别,以及为什么prop()现在更可取。 prop()是2011年5月在jQuery 1.6中引入的。

$('#frm input[type="radio":checked]').each(function(){
   $(this).checked = false;  
  });

这几乎是很好的,但你错过了[0]

正确->> $(this)[0]。Checked = false;

使用这个

$("input[name='nameOfYourRadioButton']").attr("checked", false);
function setRadio(obj) 
{
    if($("input[name='r_"+obj.value+"']").val() == 0 ){
      obj.checked = true
     $("input[name='r_"+obj.value+"']").val(1);
    }else{
      obj.checked = false;
      $("input[name='r_"+obj.value+"']").val(0);
    }

}

<input type="radio" id="planoT" name="planoT[{ID_PLANO}]" value="{ID_PLANO}" onclick="setRadio(this)" > <input type="hidden" id="r_{ID_PLANO}" name="r_{ID_PLANO}" value="0" >

:D

$('input[id^="rad"]').dblclick(function(){
    var nombre = $(this).attr('id');
    var checked =  $(this).is(":checked") ;
    if(checked){
        $("input[id="+nombre+"]:radio").prop( "checked", false );
    }
});

每次双击选中的单选,选中的单选就变为false

我的无线电以id=radxxxxxxxx开头,因为我使用这个id选择器。