gpt4 book ai didi

javascript - Safari/WebKit 的 console.log DOM 节点作为对象?

转载 作者:可可西里 更新时间:2023-11-01 01:38:52 24 4
gpt4 key购买 nike

这让我抓狂了一段时间。当我 console.log 一个 DOM 节点(通过示例从 document.getElementById 返回)时,它显示为一个交互式 html 元素,就像它出现在“元素”选项卡上一样。

这肯定很方便,但有时我只想展开对象并查看其所有属性,就像我可以对登录到控制台的所有其他类型的对象一样。

有什么方法可以让 DOM 节点作为常规对象显示在控制台中?

最佳答案

使用 console.dir 而不是 console.log

console.log( document.body );
<body class="question-page">...</body>

console.dir( document.body );
> HTMLBodyElement
aLink: ""
attributes: NamedNodeMap
background: ""
...

From the Firebug docs:

console.dir(object)

Prints an interactive listing of all properties of the object. This looks identical to the view that you would see in the DOM tab.

Chrome 也支持 console.diras shown here (未显示为 console 的属性,但它可用)

enter image description here

关于javascript - Safari/WebKit 的 console.log DOM 节点作为对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7756340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com