Chrome中的$变量? [英] $ Variable in Chrome?

查看:162
本文介绍了Chrome中的$变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在没有jQuery的页面(或任何其他使用 $ 标记作为快捷方式的图书馆)的页面上使用了Google Chrome的开发人员工具。
当我通过控制台检查 $ 时(通过输入并按回车键),我得到了这个结果:

  
函数(){[native code]}

因此,chrome具有一些本地函数,可以通过 $ 引用它。只有铬似乎有这个,我不能通过 window ['$'] ,也不通过 document ['$'] 这个['$']



我无法知道这个函数是什么。你知道它做了什么,也许有一些背景资料吗?
提前致谢!

解决方案

这已经改变了,即使从去年开始。 b
$ b devtools控制台提供 $ 作为 document.querySelector 的别名使用许多其他内容;这里有一个摘录清单:



  • $(选择器)使用指定的CSS选择器返回第一个DOM元素的引用。这个函数是 document.querySelector()函数的别名。

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

  • $ _ 返回最近评估过的表达式的值。

  • $ 0 $ 1 $ 2 $ 3 $ 4 元素面板中检查的最后五个DOM元素的历史参考或在配置面板中选择的最后五个JavaScript堆对象。

...以及其他一些。



请注意它如何调用 $ 一个别名 document.querySelector ,但是说 $$ 与调用文档是等价的 .querySelectorAll 。这两者似乎都不是真的; $ === document.querySelector false $$ 返回一个数组,而不是 NodeList


I was working with the developer tools of google chrome on a page without jQuery (or any other library that uses the $ sign as a shortcut). When I inspected $ by the console (by just typing it in and hitting enter), i got this:

$
function () { [native code] }

So, chrome has some native function that can be referenced by $. Only chrome seems to have this one and i cannot access it via window['$'] nor via document['$'] or this['$'].

I was not able to find out what this function is. Do you know what it does and maybe have some background information on this? Thanks in advance!

解决方案

This has changed yet again, even since just last year.

The devtools console provides $ as an alias to document.querySelector, along with many other things; here's an excerpted list:

  • $(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.

...and a bunch of others.

Note how it calls $ an alias of document.querySelector, but says $$ is "equivalent" to calling document.querySelectorAll. Neither seems to be literally true; $ === document.querySelector is false, and $$ returns an array, not a NodeList.

这篇关于Chrome中的$变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆