sel.options[sel.options.length] = new Option("a","a",true,true)
IE 和 Firefox 的 DOM 有很多地方不同的. <script type="text/javascript"> //<![CDATA[ function test(prnt){ var text='just a test'; var cld=document.createElement('option'); cld.value=0;
这样更 DOM 点, .innerText && .text 不是 DOM 语法<script type="text/javascript"> //<![CDATA[ function test(prnt){ var text=document.createTextNode('just a test'); var cld=document.createElement('option'); cld.value=0;
倒, 上瘾了, DOM 化...<script type="text/javascript"> //<![CDATA[ function test(prnt){ var text=document.createTextNode('just a test'); var cld=document.createElement('option'); cld.setAttribute('value', 0);
//<![CDATA[
function test(prnt){
var text='just a test';
var cld=document.createElement('option');
cld.value=0;
cld.text=text; // Firefox
cld.innerText=text; // IE
prnt.appendChild(cld);
}
//]]>
</script>
<select id="sel">
</select>
<br /><button onclick="test(document.getElementById('sel'))">appendChild</button>
//<![CDATA[
function test(prnt){
var text=document.createTextNode('just a test');
var cld=document.createElement('option');
cld.value=0;
cld.appendChild(text);
prnt.appendChild(cld);
}
//]]>
</script>
<select id="sel">
</select>
<br /><button onclick="test(document.getElementById('sel'))">appendChild</button>
//<![CDATA[
function test(prnt){
var text=document.createTextNode('just a test');
var cld=document.createElement('option');
cld.setAttribute('value', 0);
cld.appendChild(text);
prnt.appendChild(cld);
//alert(document.body.innerHTML);
}
//]]>
</script>
<select id="sel">
</select>
<br /><button onclick="test(document.getElementById('sel'))">appendChild</button>