javascript - Chrome 中的 $ 变量(美元符号)?

标签 javascript google-chrome google-chrome-devtools dollar-sign

我在没有 jQuery(或任何其他使用 $ 符号作为快捷方式的库)的页面上使用 google chrome 的开发人员工具。 当我通过控制台检查 $ 时(只需输入并按 Enter 键),我得到了:

$
function () { [native code] }

所以,chrome有一些原生函数可以通过$引用。只有 chrome 似乎有这个,我无法通过 window['$'] 或通过 document['$']this['$'] 访问它]

我无法找出这个功能是什么。您知道它的作用吗?也许有一些相关的背景信息? 提前致谢!

最佳答案

即使从去年开始,情况又发生了变化。

devtools 控制台提供 $ 作为 document.querySelector 的别名,以及 many other things ;以下是摘录列表:

  • $(selector) returns the reference to the first DOM element with the specified CSS selector. This function is an alias for the document.querySelector() function.
  • $$(selector) returns an array of elements that match the given CSS selector. This command is equivalent to calling document.querySelectorAll().
  • $_ returns the value of the most recently evaluated expression.
  • The $0, $1, $2, $3 and $4 commands work as a historical reference to the last five DOM elements inspected within the Elements panel or the last five JavaScript heap objects selected in the Profiles panel.

...还有其他一些。

请注意它如何调用 $ document.querySelector 的别名,但表示 $$ 与调用 document “等效” .querySelectorAll。从字面上看,这两种情况似乎都不是真的。 $ === document.querySelectorfalse,并且 $$ 返回一个 array,而不是 节点列表.

关于javascript - Chrome 中的 $ 变量(美元符号)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47290639/

相关文章:

javascript - Chart.js - 样式图例 : smaller circles

javascript - 无法在 okta POST/ session API 调用中使用 SessionToken 创建 session

google-chrome - 如何以编程方式安装 Chrome 扩展程序?

javascript - 内容安全策略 : cannot load Mixpanel in Chrome extension

google-chrome - 来自命令行的 chrome DevTools 的深色主题

javascript - 在 BootStrap 模态对话框中包含 HTML 代码

javascript - SailsJs 将函数调用到同一个 Controller 中

javascript - 如何防止在 chrome 上向上滚动 href ="#"

javascript - 如何链接 GCM chrome 推送通知和负载数据?

javascript - 为来自特定域的页面启用 Devtools 扩展?