JavaScript menambahkan item data ke daftar drop-down.html
Salinan kode adalah sebagai berikut:
<! Doctype html>
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "konten tipe" content = "text/html; charset = utf-8"/>
<Title> Tambahkan item data secara dinamis ke daftar drop-down </iteme>
<type skrip = "Teks/JavaScript">
fungsi gel (id) {return document.getElementById (id); }
window.onload = function () {
var cbbyear = gel ("mySel");
untuk (var i = 1990; i <2014; i ++) {
// Metode 1
/*var opt = document.createElement ("opsi");
opt.innerhtml = i;
cbbyear.appendChild (opt);*/
// Metode 2
var opt = opsi baru (i, i);
cbbyear.options.add (opt);
}
};
</script>
</head>
<body>
<pilih id = "mySel">
</pilih>
</body>
</html>