jQuery这个选择器 [英] jQuery this selector
问题描述
我做了一些谷歌搜索,但找不到有关$(this)
的更多信息.我有点愚蠢的问,但我想知道它到底是如何工作的.我想我读到它将元素变成一个对象,但是我找不到关于此的其他信息.如果有人可以提供资源,那就太好了.
I did a little Googling, and I couldn't find more information about the $(this)
. I feel a little silly asking, but I am want to know how exactly does it work. I think I read that it turns the element into an object, but I couldn't find additional information on this. If anyone could provide resources, it would be great.
I am actually trying to understand this question that I asked earlier: How can I fade only 1 div on mouseover when the classes applies to 5 other divs?
我只想对发生的任何事情进行详尽的解释,为什么它会起作用$(this)
.
I just want a thorough explanation for what is happening any why did it work $(this)
.
推荐答案
this
是JS中的一项特殊著作.它代表我当前所处的环境".因此,在您的示例中,this
引用了 specific div,该div具有当前将鼠标置于其上的测试类(哇,在那儿令人困惑……请参见下文). $()是对象的包装,该对象直接返回jQuery对象而不是元素.
this
is a special work in JS. It stands for "the context I am in at the current moment." So, in your example, this
referred to the specific div which had the test class that currently had the mouse over it (wow, confusing there... see below). $() is a wrapper around an object which returns a jQuery object instead of the element directly.
所以
-
$("div.test").mouseenter
分配一个侦听器,以便当鼠标进入div时触发
该函数内部的 -
this
指的是输入的特定div. -
$()
总是返回parens内部内容的jQuery增强版本.
$("div.test").mouseenter
assigns a listener so that when a mouse enters the div it firesthis
inside of that function refers to the specific div entered.$()
always returns a jQuery augmented version of whatever is inside the parens.
这篇关于jQuery这个选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!