如何取消选中单选按钮? [英] How to uncheck a radio button?

查看:166
本文介绍了如何取消选中单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have group of radio buttons that I want to uncheck after an AJAX form is submitted using jQuery. I have the following function:

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

借助此功能,我可以清除文本框中的值,但我无法清除单选按钮的值。

With the help of this function, I can clear the values at the text boxes, but I can't clear the values of the radio buttons.

顺便说一句,我也试过 $(this).val( ); 但是没有用。

By the way, I also tried $(this).val(""); but that didn't work.

推荐答案

(普通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中引入的。

See jQuery prop() help page for an explanation on the difference between attr() and prop() and why prop() is now preferable.
prop() was introduced with jQuery 1.6 in May 2011.

这篇关于如何取消选中单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆