将$(this)存储在变量中 [英] Storing $(this) in a variable
本文介绍了将$(this)存储在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我想将this
另存为jQuery DOM对象,然后选择它,我应该使用下面的哪种方法?
If I want to save this
as a jQuery DOM object and then select it, which method below should I use?
var element = $(this)
然后选择
$(element)
或者简单地
var element = this
此外,如果我想将element
连接到更大的选择器中,是这样的:
Also, if I want then to concatenate element
into a larger selector, is this:
$(element + " .class")
正确的方法?
推荐答案
var element = $(this)
然后可以使用element
代替$(this)
.您不必再将element
插入$()
.
Then you can use element
instead of $(this)
. You don't have to insert element
into $()
anymore.
例如:element.remove()
而不是$(this).remove()
这篇关于将$(this)存储在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文