js動態生成下拉列表


<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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM