Die Codekopie lautet wie folgt:
<! DocType html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transsitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<kopf>
<meta http-äquiv = "content-type" content = "text /html; charset = gb2312" />
<title> Verwenden Sie DOM, um das Dropdown-Listenfeld zu generieren </title>
</head>
<Body Onload = "setfun ()">
<form>
<select name = "area" id = "ase">
<option value = "0"> nein Region </Option>
</select>
</form>
<script Language = "JavaScript">
Funktion setfun () {
var id = New Array (1,2,3);
var value = new Array ("Guizhou", "Chongqing", "Sichuan");
var select = document.getElementById ("Bereich");
select.length = 1; // setzen Sie nur eine Auswahl
select.options [0] .Selected = true; // Setzen Sie, dass der erste standardmäßig ausgewählt wird
für (var x = 0; x <id.length; x ++) {
var option = document.createelement ("Option");
option.setAttribute ("value", id [x]); // Optionsattributwert festlegen
Option.AppendChild (document.CreateTextNode (Wert [x]));
select.AppendChild (Option); // Option zum Auswählen hinzufügen
}
}
</script>
</body>
</html>