function createDocument() { var xmlDoc; if (window.ActiveXObject) { var versions = [ "Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0" ]; for (var i = 0; i < versions.length; i++) { try { xmlDoc = new ActiveXObject(versions[i]); return xmlDoc; } catch (error) { //do nothing here. } } } else if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("","",null); return xmlDoc; } return null; } 使用时, var xmlDoc = createDocument(); xmlDoc.async = false; xmlDoc.load("myfile.xml");