.innerHTML无法在IE中运行

时间:2013-08-25 23:58:08

标签: javascript html internet-explorer

我正在处理一个基于onChange事件中另一个选择框填充的选择框。它适用于IE浏览器。

function getVersion(str){
if (str==""){
    document.getElementById("vSelect").innerHTML="<option value=''>Please Select a product</option>";
return;
}

if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    document.getElementById("vSelect").innerHTML=xmlhttp.responseText;
  }
}
xmlhttp.open("GET","includes/version.php?product="+str,true);
xmlhttp.send();
}

它改变了这个

<label>Version: </label>
<select id='vSelect'>
    <option value=''>Please Select a product</option>
</select>
在IE中,当onchange触发它时,它只清除select的文本。有任何想法吗?我想在不加载库的情况下这样做。

2 个答案:

答案 0 :(得分:-1)

您无法在IE中更改<select>的内容。您必须替换整个<select>元素

答案 1 :(得分:-1)

在IE中有一个已知的错误,微软确认了&#34; innerHTML&#34;无法在IE中选择对象,它在此page中声明。他们给出了解决方法,建议在select标签周围包装div并使用innerHTML。请参阅相同的解决方法页面。希望这会有所帮助。

相关问题