JavaScriptは、データ項目をドロップダウンList.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>
<選択id = "mysel">
</select>
</body>
</html>