<html>
<head>
<script>
var arrayNation = new Array('汉族','蒙古族','彝族','侗族','哈萨克族');
var arrayDegree = new Array('小学','初中','高中','中专','大专','本科','硕士','博士');
function createSelect(name, str){
var _select = document.createElement("select");
var firstOption = document.createElement("option");
firstOption.value = "------select------";
firstOption.text = "------请选择------";
_select.appendChild(firstOption);
for ( i = 0; i < str.length; i++){
var _option = document.createElement("option");
_option.value = str[i];
_option.text = str[i];
if (name == str[i]){
_option.selected = "true";
}
_select.appendChild(_option);
}
return _select;
}
</script>
</head>
<body>
<div id="nation">民族:</div>
<div id="degree">学历:</div>
<script>
document.getElementById("nation").appendChild(createSelect('侗族', arrayNation));
document.getElementById("degree").appendChild(createSelect('初中', arrayDegree));
</script>
</body>
</html>
我的js动态生成下拉列表框
最新推荐文章于 2024-08-18 12:24:07 发布