【问题标题】:What is $$ and $x in Chrome Javascript console?Chrome Javascript 控制台中的 $$ 和 $x 是什么?
【发布时间】:2022-02-09 13:13:55
【问题描述】:

我在测试 JQuery 时看到了 Chrome 的自动完成建议,并看到定义了 $$$x。它们是什么,它们来自哪里?我看到了What is the variable $x used for in Chrome?,但是$$是什么?

> $
  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


【解决方案1】:

$$(selector):

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

【讨论】:

    【解决方案2】:

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

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

    我已经检查了 Chrome 和 Firefox,这似乎对两者都是正确的。

    当您链接 jQuery 时,$() 会被 jQuery 对象替换,但 $$() 仍然以其默认行为存在。对于不熟悉所有这些东西的人来说,这很令人困惑。

    【讨论】:

      【解决方案3】:

      还有$x()函数供想要使用xpath的人使用

      【讨论】:

        猜你喜欢
        • 2023-03-22
        • 1970-01-01
        • 1970-01-01
        • 2017-11-23
        • 2016-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多