Chrome Javascript 控制台中的 $$ 和 $x 是什么?

问题描述 投票:0回答:3

我在测试 JQuery 时看到了 Chrome 的自动完成建议,并看到了

$$
$x
的定义。它们是什么以及它们来自哪里?我看到了 Chrome 中变量 $x 的用途是什么?,但是
$$
是什么?

> $
  function ( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context, rootjQuery );
    } jquery.js?body=1:62
> $$
  function $$() { [Command Line API] }
> $x
  function $x() { [Command Line API] }

这是 ogooglebar

javascript google-chrome
3个回答
10
投票

$$(selector)

返回与给定 CSS 选择器匹配的元素数组。这 命令相当于调用

document.querySelectorAll()
.


7
投票

我也有同样的问题。从 Ast Derek 发布的链接来看,默认情况下存在以下对象:

$() is an alias for document.querySelector()
$$() is an alias for document.querySelectorAll()

我检查了 Chrome 和 Firefox,这些似乎都适用。

当您链接 jQuery 时,$() 会被 jQuery 对象替换,但 $$() 仍然以其默认行为存在。对于刚接触这些东西的人来说非常困惑。


2
投票

对于那些想要使用 xpath 的人来说,还有 $x() 函数

例如

$x("//div")

有关 xpath 语法,请参阅:https://devhints.io/xpath

© www.soinside.com 2019 - 2024. All rights reserved.