نسخة الكود كما يلي:
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html ؛ charset = gb2312" />
<title> استخدم DOM لإنشاء مربع القائمة المنسدلة </title>
</head>
<body onload = "setFun ()">
<Porm>
<حدد name = "area" id = "area">
<value Option = "0"> لا توجد منطقة </option>
</select>
</form>
<script language = "javaScript">
وظيفة setFun () {
VAR ID = صفيف جديد (1،2،3) ؛
var value = new array ("Guizhou" ، "Chongqing" ، "Sichuan") ؛
var select = document.getElementById ("المنطقة") ؛
SELECT.LENGTH = 1 ؛ // تعيين اختيار واحد فقط
select.options [0] .selected = true ؛ // تم تحديد أول واحد بشكل افتراضي
لـ (var x = 0 ؛ x <id.length ؛ x ++) {
VAR OPTION = document.createElement ("Option") ؛
Option.SetAttribut
Option.AppendChild (document.createTextNode (value [x])) ؛
SELECT.APPENDCHILD (خيار) ؛ // إضافة خيار لتحديد
}
}
</script>
</body>
</html>