JavaScript fügt Datenelemente zur Dropdown-Liste hinzu.html
Die Codekopie lautet wie folgt:
<! DocType html>
<html xmlns = "http://www.w3.org/1999/xhtml">
<kopf>
<meta http-äquiv = "content-type" content = "text/html; charset = utf-8"/>
<titels> Fügen Sie dynamisch Datenelemente zur Dropdown-Liste </title> hinzu
<script type = "text/javaScript">
Funktion gel (id) {return document.getElementById (id); }
window.onload = function () {
var cbByear = Gel ("mysel");
für (var i = 1990; i <2014; i ++) {
// Methode 1
/*var opt = document.createelement ("option");
opt.innerhtml = i;
cbbyear.appendchild (opt);*/
// Methode 2
var opt = neue Option (i, i);
CBByear.options.Add (opt);
}
};
</script>
</head>
<body>
<select id = "mysel">
</select>
</body>
</html>