我希望在javascript中获得完整的html页面,除了几个div,并且应用了特定的类。我使用它来获取我的文档的完整html
$(window.document.documentElement).html().toString()
答案 0 :(得分:1)
您可以尝试:
$(document).contents().not('.aClass').foo()
答案 1 :(得分:0)
我建议如下:
var html = $('html').clone(true);
html.find('.remove').remove();
console.log(html)
请注意,如果您尝试链接html.toString()
,则最终会使用字符串[object Object]
,而不是HTML。如果您在.toString()
之后添加remove()
,则在Chrome中,您似乎最终会将相同的对象传递到控制台。
参考文献:
答案 2 :(得分:0)
首先使用.clone()创建documentElement的副本,然后将其存储在变量中。
在复制的文档中,删除所需的元素。
var doc = $(window.document.documentElement).clone();
doc.find('.remove').remove();
console.log(doc.html());