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

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

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

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


当前回答

Try

$(this).removeAttr('checked')

因为很多浏览器会把'checked=anything'解释为真。这将完全删除checked属性。

希望这能有所帮助。

其他回答

你可以使用JQuery来取消选中单选按钮

$('input:radio[name="IntroducerType"]').removeAttr('checked');
                $('input:radio[name="IntroducerType"]').prop('checked', false);

Try

$(this).removeAttr('checked')

因为很多浏览器会把'checked=anything'解释为真。这将完全删除checked属性。

希望这能有所帮助。

$('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选择器。

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

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

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

你不需要each函数

$("input:radio").attr("checked", false);

Or

$("input:radio").removeAttr("checked");

同样也应该适用于你的文本框:

$('#frm input[type="text"]').val("");

但是你可以改进它

$('#frm input:text').val("");