本文介紹了JavaScript innerHTML 不適用于 IE?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在使用 ajax 調(diào)用為我的下拉列表帶來列表并將其分配給 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中嘗試添加或更新表單元素時出現(xiàn)問題,解決方法是創(chuàng)建一個div并設(shè)置附加到 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);
這篇關(guān)于JavaScript innerHTML 不適用于 IE?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!