復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>利用dom生成下拉列表框</title>
</head>
<body>
<form>
<select>
<option value="0">沒有地區</option>
</select>
</form>
<script language="javascript">
function setFun(){
var id = new Array(1,2,3);
var value = new Array("貴州","重慶","四川");
var select = document.getElementById("area");
select.length = 1;//設置只能選擇一個
select.options[0].selected = true;//設置默認選中第一個
for(var x = 0;x<id.length;x++){
var option = document.createElement("option");
option.setAttribute("value",id[x]);//設置option屬性值
option.appendChild(document.createTextNode(value[x]));
select.appendChild(option);//向select增加option
}
}
</script>
</body>
</html>
新聞熱點
疑難解答
圖片精選