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">
ฟังก์ชั่นเจล (id) {return document.getElementById (id); -
window.onload = function () {
var cbbyear = gel ("mysel");
สำหรับ (var i = 1990; i <2014; i ++) {
// วิธี 1
/*var opt = document.createElement ("ตัวเลือก");
opt.innerhtml = i;
cbbyear.appendchild (opt);*/
// วิธี 2
var opt = ตัวเลือกใหม่ (i, i);
cbbyear.options.add (opt);
-
-
</script>
</head>
<body>
<เลือก id = "mysel">
</เลือก>
</body>
</html>