即使没有JQuery,JavaScript中的美元符号是否也定义?
我知道$(“ ...”)
当然是在jquery中定义的( javaScript 中的“ $”符号的含义是什么,而且有些不使用jQuery的人define $ = document.queryselector
或$ = document.queryselector.bind(document)
。
在某些情况下(Firefox,Chrome),$
似乎也可以在开发人员控制台中使用,即使不加载此库,也没有手动定义$
:请参阅<<。 a href =“ https://stackoverflow.com/questions/222244823/what-is-the-dollar-sign-in-sign-in-javascript-if-not-jquery”> javascript中的美元符号是什么,如果不是jquery 。
问题:我们可以在2022年假设$
是大多数浏览器的别名document.queryselector
,我们可以直接在JS代码中使用它吗?
我知道caniuse.com,但这里都不 https://caniuse.com/?search=%24 nor https://caniuse.com/?search=dollar 帮助了。
示例:打开一个包含的HTML文件:
<html>
<head></head>
<body>
<div id="a">Hello world</div>
</body>
</html>
打开开发人员控制台并执行$('#a')
:它有效。
I know that $("...")
is of course defined in jQuery (What is the meaning of "$" sign in JavaScript), and also that some people who don't use jQuery define $ = document.querySelector
or $ = document.querySelector.bind(document)
.
In some cases (Firefox, Chrome), $
seems to be available in the developer console even without loading this library, or without defining $
manually: see the main answer of What is the dollar sign in Javascript, if not jQuery.
Question: can we assume in 2022 that $
is an alias in most browsers for document.querySelector
and can we use it directly in our JS code?
I know caniuse.com but here neither https://caniuse.com/?search=%24 nor https://caniuse.com/?search=dollar helped.
Example: open a html file containing:
<html>
<head></head>
<body>
<div id="a">Hello world</div>
</body>
</html>
Open the developer console and do $('#a')
: it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不能。它是仅在某些浏览器中的开发人员控制台中可用的,而无需导入
jquery
库。参见 https:// https://developer.chrome.chrome.com/docs/docs/devtools/devtools/devtools/控制台/实用程序/#queryselector-function :
这是一个简单的例子:
No you can't. It's only available in developer console in some browsers without importing
jQuery
library.See https://developer.chrome.com/docs/devtools/console/utilities/#querySelector-function:
Here is a simple example: