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

标签 javascript dom safari

这让我抓狂了一段时间。当我 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/

相关文章:

javascript - 停止特定元素 ID 上的其他点击事件 - JQuery

javascript - jQuery:输入选择中的字符串插值

javascript - 如何获取 <td> 内的跨度值(表数据),当单击也在 <td> 内的按钮时

Javascript:尝试从循环中删除选项

javascript - 阿拉伯字符在 JavaScript 中无法正确显示

javascript - 如何在从 firebase 检索的字符串中设置单词的样式?

javascript - 如何在 html5 中使用包含大量单独 svg 的 svg 文件?

ios - 如何在 iOS Safari(在实际设备上)中将 "crop"关闭屏幕 <div>?

html - 如何更改 Safari Web Apps 的 iOS 状态栏的背景颜色?

带有表单元素的 CSS float div 在 mac 上的 Safari 3 中消失