在 Firefox 中解析 XmlHttpRequest 的 HTML 结果(获取 DOM 树)的最佳方法是什么?
EDIT:
I do not有DOM树,我想获取它。
XmlHttpRequest 的“responseXML”仅在结果是实际 XML 时才起作用,因此我只能使用responseText。
The innerHTML hack doesn't seem to work with a complete HTML document (in <html></html>). - turns out it works fine.
innerHTML
应该可以正常工作,例如
// This would be after the Ajax request:
var myHTML = XHR.responseText;
var tempDiv = document.createElement('div');
tempDiv.innerHTML = myHTML.replace(/<script(.|\s)*?\/script>/g, '');
// tempDiv now has a DOM structure:
tempDiv.childNodes;
tempDiv.getElementsByTagName('a'); // etc. etc.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)