js查看html自身页面源代码

发布时间:2017年12月19日 作者:未知 查看次数:1147

document.body 与 document.documentElement

document.body 是 body节点 

document.documentElement 是 html 根节点

<!DOCTYPE html>

<html lang="en"><head>    <meta charset="UTF-8">    <title></title>

</head>

<body>

<div class="container"></div>

<script>   alert(document.body.outerHTML);   alert(document.documentElement.outerHTML);

</script>

</body>

</html>


==========================

javascript查看html自身页面源代码

==========================


<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title>设置查看</title>

</head>

<body style="background-color: Black;">


<textarea id="ShowID" rows="30" cols="200"></textarea>


    <script type="text/javascript" language="javascript">

var sTxt=document.getElementById("ShowID");

sTxt.value=document.documentElement.outerHTML;

    </script>


</body>

</html>




版权所有!www.sieye.cn
E.Mail:sieye@sohu.com QQ:66697110