这不是$(this) [英] This but not $(this)

查看:90
本文介绍了这不是$(this)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,在jQuery中是这样的

OK so in jQuery;

我有一个选择器$("#gmap")

我想在选择器的上下文中做很多代码.我一直都很懒惰,并使用.each(),尽管只有一个.

I want to do alot of code in context of my selector. I have always been lazy and used .each() even though there is only one of them.

$("#gmap321654987789").each(function(){
 $(this).....
});

这特别有趣吗?我讨厌感觉不对的代码.

Is this particuarly effitiant? I hate code that doesn't feel 'right'.

是否存在说...或类似内容的机制.

Is there a mechanism for say... or something similar.

$("#gmap321654987789").this(function(){
 $(this).....
});

推荐答案

只需缓存对象并像平常一样使用它即可:

Just cache the object and work with it like normal:

var $gmap = $('#gmap321654987789'); // Get your jQuery object
console.log($gmap);
console.log($gmap.text());

这篇关于这不是$(this)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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