<html>
<body onload="init()">
<div id="test"><div>
<script>
function init() {
aSelect = document.createElement("select");
aSelect.name = 'test';for(var i = 1; i <=5; i++) {
aOption = document.createElement("option");
aOption.value = i;
aOption.text = i;
if(i == 3) {
aOption.selected = true;
}
aSelect.options.add(aOption);
}
document.getElementById("test").appendChild(aSelect);
}
</script>
</body>
</html>
这段js代码,在IE6浏览器下,默认当前选中的值是2,而在火狐浏览器下默认选中的是3
如何修改,让他在IE6浏览器下,默认当前选中的值也是3.
<body onload="init()">
<div id="test"><div>
<script>
function init() {
aSelect = document.createElement("select");
aSelect.name = 'test';for(var i = 1; i <=5; i++) {
aOption = document.createElement("option");
aOption.value = i;
aOption.text = i;
if(i == 3) {
aOption.selected = true;
}
aSelect.options.add(aOption);
}
document.getElementById("test").appendChild(aSelect);
}
</script>
</body>
</html>
这段js代码,在IE6浏览器下,默认当前选中的值是2,而在火狐浏览器下默认选中的是3
如何修改,让他在IE6浏览器下,默认当前选中的值也是3.
window.sidebar -->FF
<html>
<body onLoad="init()">
<div id="test"><div>
<script>
function init() {
aSelect = document.createElement("select");
aSelect.name = 'test';
for(var i = 1; i <=5; i++) {
aSelect.options[i-1]=new Option(i,i,false,false);
}
//(3-1)索引是从0开始所以3选中要3-1
aSelect.options.selectedIndex=(3-1)
document.getElementById("test").appendChild(aSelect);
}
</script>
</body>
</html>
ie6 ie8 fx chrome 所有选项都是3