问问题
134 次
2 回答
1
我的快速示例:
<select multiple id="select">
<option value="1">1</option>
<option value="2" class="toselect">2</option>
<option value="3">3</option>
<option value="4" class="toselect">4</option>
<option value="5">5</option>
</select>
<script type="text/javascript">
var select = document.getElementById("select");
var select_options = select.getElementsByClassName("toselect");
for (var i = 0; typeof(select_options) != "undefined"; i++) {
select_options[i].selected = true;
}
</script>
在这里,我使用类名来指定需要选择的选项。你可以使用任何你想要的东西。
于 2012-10-27T14:54:51.857 回答
0
像这样的东西:
var selectBox = document.getElementById('selectbox');
selectBox.children[1].selected = true;
完整示例:jsFiddle
于 2012-10-27T14:54:46.100 回答