繁体   English   中英

如何获取 html body 标签的所有数据到 javascript 中的结束 body 标签?

[英]how to get all the data of html body tags to ending body tags in javascript?

相同类型的问题: 使用纯 javascript 获取 body 标签中的所有元素

我在 HTML 文件中有一个非常大的 HTML、CSS 和 javascript 代码,所以我想以快捷方式显示它们

认为;

<body>
   <div class="w3-red">
       <h1> this is <h1>
   </div>
   <div class="w3-red">
       <h1> this is <h1>
   </div>
   <div class="w3-red">
       <h1> this is <h1>
   </div>
</body>
<p id="demo"></p>

我想在 javascript 中捕获 HTML body 标记内的数据并分配给变量

分配给变量结果与上面的代码相同

这是javascript代码

<script>
   var myCollection = document.body.getElementsByTagName("*");
   document.getElementById("demo").innerHTML =
     "The innerHTML of the second paragraph is: " +
     myCollection[2].innerHTML;
</script>

我想这可以帮助你,如果你看看:

 $("body").get(); //Returns a body Object

$("body").get()[0].children //Returns all html tags directly below the body tag

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM