jQuery这个选择器 [英] jQuery this selector

查看:107
本文介绍了jQuery这个选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些谷歌搜索,但找不到有关$(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.

所以

  1. $("div.test").mouseenter分配一个侦听器,以便当鼠标进入div时触发
  2. 该函数内部的
  3. this指的是输入的特定div.
  4. $()总是返回parens内部内容的jQuery增强版本.
  1. $("div.test").mouseenter assigns a listener so that when a mouse enters the div it fires
  2. this inside of that function refers to the specific div entered.
  3. $() always returns a jQuery augmented version of whatever is inside the parens.

这篇关于jQuery这个选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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