怎样把javascript中的数组值赋到js下拉列表?请教高手!!!!
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>appendChild</title>
</head>
<body>
<select id="list"></select>
<script type="text/javascript">
var arr = ["第一项","第二项","第三项","第四项","第五项"];
var o = document.getElementById("list");
var len = arr.length;
for(var i = 0; i < len; i++){
var op = document.createElement("option");
op.setAttribute("value",arr[i]);
op.innerHTML = arr[i];
o.appendChild(op);
}
</script>
</body>
</html>
这样应该可以看懂了,嘿嘿,祝你好运!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>appendChild</title>
</head>
<body>
<select id="list"></select>
<script type="text/javascript">
var arr = ["第一项","第二项","第三项","第四项","第五项"];
var o = document.getElementById("list");
var len = arr.length;
for(var i = 0; i < len; i++){
var op = document.createElement("option");
op.setAttribute("value",arr[i]);
op.innerHTML = arr[i];
o.appendChild(op);
}
</script>
</body>
</html>
这样应该可以看懂了,嘿嘿,祝你好运!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询