我尝试使用jQuery选中单选按钮。这是我的代码:
<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>
而 JavaScript 的代码是:
jQuery("#radio_1").attr('checked', true);
无法正常工作:
jQuery("input[value='1']").attr('checked', true);
无法正常工作:
jQuery('input:radio[name="type"]').filter('[value="1"]').attr('checked', true);
无效:
你有其他想法吗?我错过了什么吗?
jQuery("#type").buttonset();
但在检查单选按钮之前进行此更改会破坏单选按钮集(不知道为什么)。 最后,我在检查单选按钮后调用buttonset,它完美地工作了。 - Alexis