本文介紹了JavaScript innerHTML 不適用于 IE?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用 ajax 調用為我的下拉列表帶來列表并將其分配給 html,適用于 mozilla nad crome 但對于 IE,它顯示一個空白下拉列表
I am using ajax call for to bring the list for my drop down and assign it to html,works fine for mozilla nad crome but for IE it displays a blank dropdown
var xmlhttp;
var strURL = "selectedu.php?selectward="+selectward;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(xmlhttp.responseText=="NOER")
{
alert("Select ER Type");
}
else
{
document.getElementById(id).innerHTML=xmlhttp.responseText;
}
}
}
xmlhttp.open("GET",strURL,true);
xmlhttp.send();
推薦答案
innerHTML
屬性在IE中嘗試添加或更新表單元素時出現問題,解決方法是創建一個div并設置附加到 DOM 之前的 innerHtml 屬性:
The innerHTML
property has some problems in IE when trying to add or update form elements, the workaround is to create a div and set the innerHtml property on that before appending to the DOM:
var newdiv = document.createElement("div");
newdiv.innerHTML = xmlhttp.responseText;
var container = document.getElementById(id);
container.appendChild(newdiv);
這篇關于JavaScript innerHTML 不適用于 IE?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!