【发布时间】:2010-06-24 02:15:14
【问题描述】:
我有一个 javascript 数组,其中包含我要检查的收音机的名称和值。
jQuery(window).load(function(){
var selected_options = new Array();
selected_options['swing_type'] = 'Slide';
var x;
for (x in selected_options){
jQuery("#menu input[name="+ x +"][value="+ selected_options[x] +"]").attr('checked', 'checked');
}
});
而 html 有类似的东西:
<td>
<input type="radio" id="swing" name="swing_type" value="Swing" /><label for="swing"> Swing</label><br />
<input type="radio" id="slide" name="swing_type" value="Slide" /><label for="slide"> Slide</label>
</td>
当我运行此脚本时,浏览器变得无响应。我尝试了一些变体,以下两个有效:
jQuery("#menu input[value="+ selected_options[x] +"]").attr('checked', 'checked');
jQuery("#menu input[name=swing_type][value=Swing]").attr('checked', 'checked');
以下操作无效:
jQuery("#menu input[name=swing_type][value="+ selected_options[x] +"]").attr('checked', 'checked');
我希望有人能告诉我什么是错的。我想定位正确的无线电输入。如果我只针对值,我可能会看到可能有两个单独的集合具有是/否值的情况。谢谢。
【问题讨论】:
标签: javascript jquery html radio-button