<html>
<head></head>
<body onload="addOptions()">
<select id="selectItem">
</select>
</body>
<html>
<script type="text/javascript">
function addOptions() {
var selectItem = document.getElementById("selectItem");
var ss = "['选项1','选项2','选项3']";
var aa = eval(ss);
for(var i=0;i<aa.length;i++) {
selectItem.add(new Option(aa[i],aa[i]));
}
}
</script>
<head></head>
<body onload="addOptions()">
<select id="selectItem">
</select>
</body>
<html>
<script type="text/javascript">
function addOptions() {
var selectItem = document.getElementById("selectItem");
var ss = "['选项1','选项2','选项3']";
var aa = eval(ss);
for(var i=0;i<aa.length;i++) {
selectItem.add(new Option(aa[i],aa[i]));
}
}
</script>
本文演示了如何使用JavaScript动态加载选项到下拉菜单中,包括解析字符串数组为选项对象,并将其添加到HTML选择元素中。
873

被折叠的 条评论
为什么被折叠?



