Code
<html >
<head>
<title>sel_test</title>
</head>
<body>
<script type ="text/javascript">
var sel_text = new Array("通道1","通道2","通道3");
var sel_value = new Array("0","1","2");
<!--
function select_list(sel_num,sel_text,sel_value) {
var sel_name = document.getElementById("channal_index")
for(var i=0;i<sel_num;i++){
var option = document.createElement("option");
option.value = sel_value[i];
option.innerHTML = sel_text[i];
sel_name.appendChild(option);
}
}
-->
</script>
<body onload="select_list(3,sel_text,sel_value)">
<select id="channal_index">
</select>
</body>
</html>
思路:
1、通过getElementById来获取ID为“channal_index”的元素
2、添加option元素
3、为option元素添加属性(text,value)
4、把option节点添加到select元素中(通过select.appendChild(option))
研究了很久的,终于搞定了!