笔者开发的一个项目之前在IE 9,IE10下运行正常,这两天由于IE升级到11。它就运行不正常了,比如报了一个错误---“XSLTProcessor”未定义(当然该错误可能随着开发代码的不同稍有差别)。下边是以前的代码:
function loadXMLDoc(dname) {
if (window.ActiveXObject) { xhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); } else { xhttp = new XMLHttpRequest(); } xhttp.open("GET", dname, false); xhttp.send(""); return xhttp.responseXML;}function displayResult(xmlfile,xslfile) { xml = loadXMLDoc(xmlfile); xsl = loadXMLDoc(xslfile); // code for IE if (window.ActiveXObject) { ex = xml.transformNode(xsl); document.getElementById("modload").innerHTML = ex; } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml, document); document.getElementById("modload").appendChild(resultDocument); }} 经过调试发现,在IE 11下,它没进入“code for IE"分支。本人的解决办法是把上边红体字修改为if (window.ActiveXObject||"ActiveXObject" in window),就又可以正常运行了。