.innerHTML无法在IE中运行 [英] .innerHTML not working in IE

查看:114
本文介绍了.innerHTML无法在IE中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im working on a select box that populates based on another select box in an onChange event. It works great in every browser but 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>

当onchange触发时它只清除了select的文本。有任何想法吗?我试图在不加载库的情况下执行此操作。

in IE when the onchange fires it just clears out the text of the select. Any Ideas? I am trying to do this without loading a library.

推荐答案

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

There is a known bug in IE that microsoft confirmed "innerHTML" fails to work on the Select Object in IE and it is declared in this page. they have given the workaround suggesting to wrap a div around the select tag and to use innerHTML. see the same page for the workaround. Hope this helps.

这篇关于.innerHTML无法在IE中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆