论坛首页 Java企业应用论坛

我的js动态生成下拉列表框

浏览 4359 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-09-08  
<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>
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics