最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery Select a radio button (onclick) - Stack Overflow

programmeradmin0浏览0评论

I have a function using jquery that updates a form when an image is click.

I need to add to that function so that a specified radio button is selected.

How can I select a radio button using jquery please?

UPDATE:

I'll explain further...I have overlayed an image and hid the radio button...so what the user clicks on an image it will check the selected radio.

Here's how each radio looks like:

<label style="display: inline; " for="select_theme_a">
<img src="images/icons/theme1.png" />
<input checked="checked" class="select_control" id="select_theme_a" name="select_theme" type="radio" value="a" onclick="return submitForm();" style="display:none" />
</label>

There's 4 radio buttons .. 4 different images to click on.

Hope this helps

I have a function using jquery that updates a form when an image is click.

I need to add to that function so that a specified radio button is selected.

How can I select a radio button using jquery please?

UPDATE:

I'll explain further...I have overlayed an image and hid the radio button...so what the user clicks on an image it will check the selected radio.

Here's how each radio looks like:

<label style="display: inline; " for="select_theme_a">
<img src="images/icons/theme1.png" />
<input checked="checked" class="select_control" id="select_theme_a" name="select_theme" type="radio" value="a" onclick="return submitForm();" style="display:none" />
</label>

There's 4 radio buttons .. 4 different images to click on.

Hope this helps

Share Improve this question edited Aug 17, 2011 at 22:18 Satch3000 asked Aug 17, 2011 at 21:14 Satch3000Satch3000 49.5k90 gold badges225 silver badges349 bronze badges 2
  • Duplicate: stackoverflow./questions/977137/… – PhD Commented Aug 17, 2011 at 21:16
  • Not a duplicate...that question is about resetting / unselecting – Satch3000 Commented Aug 17, 2011 at 21:41
Add a ment  | 

2 Answers 2

Reset to default 6

How can I select a radio button using jquery please?

You can use attr method like this:

$('#radio-id').attr('checked', true);

If radio element is inside same parent element as image than you can use this piece of code inside function that handles image click event:

$(this).parent().find(":radio").attr('checked', true);
发布评论

评论列表(0)

  1. 暂无评论