问题
I'm using jQuery and I have a group of radio buttons all with the same name, but different value properties.
For example:
<input type = "radio" name = "thename" value="1"></input>
<input type = "radio" name = "thename" value="2"></input>
<input type = "radio" name = "thename" value="3"></input>
I want to make it so they are all unselected. Current state of my page has one of them clicked. How do I do this?
回答1:
As of jQuery 1.6, $("radio").prop("checked", false);
is the suggested method.
回答2:
$("input:radio[name='thename']").each(function(i) {
this.checked = false;
});
not sure why the jquery prop doesn't work and this does...
回答3:
Try using this: $('input[type="radio"]').prop('checked', false);
Using jQuery's prop method can change properties of elements (checked, selected, ect.).
回答4:
The answer posted by @matzahboy worked perfectly.
Tried other ways but this one worked the best:
$(input[name=thename]).removeAttr('checked');
回答5:
Try the following code:
$(input[name=thename]).removeAttr('checked');
回答6:
This is the simple and generic answer (I believe):
$("input[name=NAME_OF_YOUR_RADIO_GROUP]").prop("checked",false);
For this specific question, I would use:
$("input[name=thename]").prop("checked",false);
Hope this helps
回答7:
it worked for me;
$('input[name="radioName"]').attr('checked', false);
回答8:
function resetRadio(name) {
$('#form input:radio[name=' + name + ']:checked').each(function () {
var $this = $(this);
$this.prop("checked", false);
});
}
$('#form input:radio').on('dblclick', function () {
var $this = $(this);
var name = $this.prop('name');
resetRadio(name);
});
This allows you to double click the radios to reset them.
回答9:
To unselect all the radios of a group called "namegroup", try this:
$("input[type=radio][name=namegroup]").prop("checked", false);
回答10:
This is simple and works for me.
Try this one:
$('input:radio[name="gender"]').attr('checked',false);
Try this one:
$('input[name="gender"]').prop('checked', false);
来源:https://stackoverflow.com/questions/7044301/unselect-group-of-radio-buttons-using-jquery