问题描述
在 Google Chrome 的开发人员工具中,当我选择一个元素时,我会在所选元素旁边看到 ==$0
.这是什么意思?
In Google Chrome's developer tools, when I select an element, I see ==$0
next to the selected element. What does that mean?
推荐答案
它是最后选择的 DOM 节点索引.Chrome 会为您选择的每个 DOM 节点分配一个索引.所以 $0
将始终指向您选择的最后一个节点,而 $1
将指向您之前选择的节点.把它想象成一堆最近选择的节点.
It's the last selected DOM node index. Chrome assigns an index to each DOM node you select. So $0
will always point to the last node you selected, while $1
will point to the node you selected before that. Think of it like a stack of most recently selected nodes.
例如,考虑以下内容
<div id="sunday"></div>
<div id="monday"></div>
<div id="tuesday"></div>
现在您打开了 devtools 控制台并按上述顺序选择了 #sunday
、#monday
和 #tuesday
,您将获得类似的 id:
Now you opened the devtools console and selected #sunday
, #monday
and #tuesday
in the mentioned order, you will get ids like:
$0 -> <div id="tuesday"></div>
$1 -> <div id="monday"></div>
$2 -> <div id="sunday"></div>
注意:知道节点在脚本(或控制台)中是可选的可能很有用,例如一个流行的用途是角度元素选择器,所以你可以简单地选择你的节点,然后运行:
Note:It Might be useful to know that the node is selectable in your scripts (or console), for example one popular use for this is angular element selector, so you can simply pick your node, and run this:
angular.element($0).scope()
瞧,您可以通过控制台访问节点范围.
Voila you got access to node scope via console.
这篇关于==$0(double 等于零美元)在 Chrome 开发者工具中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!