问题:
I try to check a radio button with jQuery. 我尝试用jQuery检查一个单选按钮。 Here's my code: 这是我的代码:
<form>
<div id='type'>
<input type='radio' id='radio_1' name='type' value='1' />
<input type='radio' id='radio_2' name='type' value='2' />
<input type='radio' id='radio_3' name='type' value='3' />
</div>
</form>
And the JavaScript: 和JavaScript:
jQuery("#radio_1").attr('checked', true);
Doesn't work: 不起作用:
jQuery("input[value='1']").attr('checked', true);
Doesn't work: 不起作用:
jQuery('input:radio[name="type"]').filter('[value="1"]').attr('checked', true);
Doesn't work: 不起作用:
Do you have another idea? 你有其他想法吗? What am I missing? 我错过了什么?
解决方案:
参考一: https://stackoom.com/question/Nlxj/如何使用jQuery检查单选按钮参考二: https://oldbug.net/q/Nlxj/How-to-check-a-radio-button-with-jQuery
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/3287170