javascript為下拉列表添加數據項.html 
復制代碼 代碼如下:
 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
<title>為下拉列表動態添加數據項</title> 
<script type="text/javascript"> 
function gel(id) { return document.getElementById(id); } 
window.onload = function() { 
var cbbYear = gel("mysel"); 
for (var i = 1990; i < 2014; i++) { 
//方法1 
/*var opt = document.createElement("option"); 
opt.innerHTML = i; 
cbbYear.appendChild(opt);*/ 
//方法2 
var opt = new Option(i, i); 
cbbYear.options.add(opt); 
} 
}; 
</script> 
</head> 
<body> 
<select> 
</select> 
</body> 
</html> 
新聞熱點
疑難解答
圖片精選