开发者

JQuery change radio buttons checked state when each is selected

开发者 https://www.devze.com 2023-03-26 03:30 出处:网络
I have three radio buttons in a search group: Zip, City and County. How can I toggle the checked states of all radio buttons in the group when one of them is clicked?

I have three radio buttons in a search group: Zip, City and County. How can I toggle the checked states of all radio buttons in the group when one of them is clicked?

开发者_StackOverflow
<input id="SC5_zipR" type="radio" value="" />
<input id="SC5_cityR" type="radio" value="" />
<input id="SC5_countyR" type="radio" value="" />

$("#SC5_zipR").prop('checked', true); //default checked value for zip code option

I am using Jquery 1.6.2. Thank you in advance, Attila


Give them all the same name. It's usually how radio buttons are done:

<input id="SC5_zipR" name="sc5" type="radio" value="zip" />
<input id="SC5_cityR" name="sc5" type="radio" value="city" />
<input id="SC5_countyR" name="sc5" type="radio" value="county" />

Demo here: http://jsfiddle.net/naveen/9jRPc/

0

精彩评论

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