1.添加option
var theColor = document.getElementById("color");
//var oOption1 = new Option("white","3");
var oOption1 = document.createElement("OPTION");
oOption1.innerHTML="white";
oOption1.value ="3";
theColor.appendChild(oOption1);
var oOption2 = document.createElement("OPTION");
oOption2.innerText = "black";
oOption2.value = "4";
theColor.options.add(oOption2);
[注]
a.
document.createElement
document.createElement("OPTION"),document.createElement("tr"),
document.createElement("table")...
b.
两种都可以使用oOptionX.selected = true来选择
而第二个则还可以通过theColor.selectedIndex =2;
或者theColor.value = "4"来选择
2.
xSelect.children(i) == xSelect.options[i]
xSelect.getElementsByTagName('option');
3.
<script>
function showOptions(){
var someNodeList = $('lstEmployees').getElementsByTagName('option');
var nodes = $A(someNodeList);
nodes.each(function(node){
alert(node.nodeName + ': ' + node.innerHTML);
});
}
</script>
<select id="lstEmployees" size="10" >
<option value="5">Buchanan, Steven</option>
<option value="8">Callahan, Laura</option>
<option value="1">Davolio, Nancy</option>
</select>
<input type="button" value="Show the options" onclick="showOptions();" >