开发者

How can I check a radio button on load, based on it's value?

I've got the value of a radio button (r1) and I'm trying to use:

$("input:radio[val=r1]").attr('checked', true);

to check it.

The thing is that I've got three radio buttons in a div, when I check one, the value of the checked button gets stored.

When I reload the page I want the page to check the radio button that was chosen las开发者_JS百科t.

Thanks!


The attribute is called value. Try:

$('input:radio[value=r1]').attr('checked', 'checked');

To uncheck you would call:

$(selector).removeAttr('checked');


The selected radio button is not natively preserved over the postbacks. It all depends on the server-side language that you use to restore the state i.e. check the respective radio button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜