$($(this))是什么意思? [英] What does $($(this)) mean?
问题描述
我在网上看到一些使用以下语句的代码
I saw some code around the web that uses the following statement
if ($($(this)).hasClass("footer_default")) {
$('#abc')
.appendTo($(this))
.toolbar({position: "fixed"});
}
$($(这是什么用途) ))
为什么这里有必要?
推荐答案
是, $ ($(this))
与 $(this)
相同, jQuery()
或 $()
功能很棒 idempotent 一>。这个特定的构造没有理由(这个
的双重包装),但是,我用它作为一个快捷方式只从一个组中获取第一个元素,这涉及类似的双重包装,是
Yes, $($(this))
is the same as $(this)
, the jQuery()
or $()
function is wonderfully idempotent. There is no reason for that particular construction (double wrapping of this
), however, something I use as a shortcut for grabbing the first element only from a group, which involves similar double wrapping, is
$($('selector')[0])
相当于,抓取匹配 selector
的每个元素(返回一个jQuery对象),然后使用 [0 ]
获取列表中的第一个(返回 DOM
对象),然后将其包装在 $()中
再次将其转换回jQuery对象,这次只包含一个元素而不是一个集合。它大致相当于
Which amounts to, grab every element that matches selector
, (which returns a jQuery object), then use [0]
to grab the first one on the list (which returns a DOM
object), then wrap it in $()
again to turn it back into a jQuery object, which this time only contains a single element instead of a collection. It is roughly equivalent to
document.querySelectorAll('selector')[0];
,这几乎相当于
document.querySelector('selector');
这篇关于$($(this))是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!