.innerHTML在IE中不起作用

.innerHTML not working in IE

本文关键字:不起作用 IE innerHTML      更新时间:2023-09-26

我正在处理一个基于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的文本。有什么想法吗?我正在尝试在不加载库的情况下执行此操作。

IE中有一个已知的错误,微软确认"innerHTML"无法处理IE中的选择对象,并在该页面中声明。他们给出了一个变通方法,建议在select标记周围包装一个div并使用innerHTML。有关解决方法,请参阅同一页。希望这能有所帮助。

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