在浏览器控制台(console)中使用jQuery选择器时,一个$号只能选择到第一个元素,而两个$$号可以选择到所有元素,为什么?

题图

img

另外,浏览器控制台和一般嵌入网页的脚本

<script></script>

相比有什么区别?为什么有时候一样的代码表现不一样?

$ 等价于 document.querySelector
$$ 等价于 document.querySelectorAll

$(selector [, startNode])
$(selector) returns the reference to the first DOM element with the specified CSS selector. When called with one argument, this function is an alias for the document.querySelector() function.

$$(selector [, startNode])
$$(selector) returns an array of elements that match the given CSS selector. This command is equivalent to calling document.querySelectorAll().

官网来源:


img

$ 和 $$ 不是同一个函数

img

$是jQuery选择器函数,而$$是浏览器控制台(console)中自带的选择器函数
两个不一样

如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632