Unchecking radiobutton list using jquery

2019-08-03 00:13发布

问题:

Ok, last question for today I promise!

I have the following line of code that features a radio button list (radTopx)

ddlBuyer.Attributes.Add("onclick", "$('#tbxProdAC').val(''); $('#txtbxHowMany').val(''); $('#GridView1').remove(); $('#radTopx').attr('checked',false); ");

What I am trying to achieve is that when ddlBuyer is clicked, radTopx has all it's radio buttons unchecked.

I am obviously doing this incorrectly at present, please can someone pointout where I have gone wrong? Does this work differently in a radio button list to a standard radio button?

Where #radTopx represents the following radio button list :

RadioButtonList ID="radTopx"

    ListItem>UUF1<ListItem>
    ListItem>UUF2<ListItem>
    ListItem>UUF3<ListItem>

RadioButtonList

回答1:

$('#ddlBuyer').click(function() {
    $('div#radios input').attr('checked',false);
});

where div#radios encloses all your radio inputs. I'm assuming ddlBuyer is the id of something that gets clicked.

We can't give an answer in regard to #radTopx since we don't know what it is.



回答2:

Thank you very much Carillonator, greatly appreciated.

The following code did the trick, I just need to add in the 'input'

ddlBuyer.Attributes.Add("onclick", "$('#tbxProdAC').val(''); $('#txtbxHowMany').val(''); $('#GridView1').remove(); $('#radTopx input').attr('checked',false); ");

Where #radTopx is the radio button list.



回答3:

$('#radTopx').prop('checked',false);