我有 HTML,我需要获取此 html 的页面源。
document.documentElement.outerHTML
或
$.ajax({
async: true,
type: 'GET',
cache: false,
url: window.location.href,
success: function(data) {
alert(data);
}
});
正在工作,但它们最初显示的是源代码。如果我更改 html(例如,通过 jQuery),他们不会阅读我的更改。
是否可以读取页面的当前源?
最佳答案
在 chrome 上试了一下,效果很好。使用
document.documentElement.innerHTML
有趣的是你的代码也能工作
document.documentElement.outerHTML
查看此 fiddle 中打印到控制台的 html .它实际上包含了 jQuery 所做的更改。
关于Javascript:获取当前页面当前源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13913824/