如何获得< html>使用JavaScript / jQuery标记HTML? [英] How to get the <html> tag HTML with JavaScript / jQuery?
问题描述
使用 $('html')。html()
我可以在< html>
标签(< head>
,< body>
等)。但是如何获得< html>
标签的实际HTML(带属性)?
Using $('html').html()
I can get the HTML within the <html>
tag (<head>
, <body>
, etc.). But how can I get the actual HTML of the <html>
tag (with attributes)?
或者,是否可以使用jQuery(或普通的旧JavaScript)获取页面的整个HTML(包括doctype,< html>
等)?
Alternatively, is it possible to get the entire HTML of the page (including doctype, <html>
, etc.) with jQuery (or plain old JavaScript)?
推荐答案
本地获取 html
元素的最简单方法是:
The simplest way to get the html
element natively is:
document.documentElement
以下是参考: https://developer.mozilla.org/en-US/docs/ Web / API / Document.documentElement 。
更新:然后获取 html
元素作为你会做的字符串:
UPDATE: To then grab the html
element as a string you would do:
document.documentElement.outerHTML
这篇关于如何获得< html>使用JavaScript / jQuery标记HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!