jQuery将$ this传递给函数参数 [英] jQuery pass $this to function parameter

查看:105
本文介绍了jQuery将$ this传递给函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

<img id="leftBubble" class="bubbles" src="left.png" />
<img id="rightBubble" class="bubbles" src="right.png" />

以及类似这样的悬停事件:

And a hover event like so:

$(".bubbles").each(function(){
    $(this).hover(function() { 
        pause($(this));
    }, function() {
        play(4000, $(this));
    });
});

我的pause()函数似乎不起作用

My pause() function does not seem to be working

function pause(pauseMe) {
    if (pauseMe == $("#leftBubble")) {
        clearTimeout(timer1);                        //this is never reached
    } else if (pauseMe == $("#rightBubble")) {
        clearTimeout(timer2);                        //nor this
    }
}

是否有任何使悬停事件将$ this用作暂停功能的参数的想法?

Any idea to make the hover event pass $this as the parameter for the pause function?

推荐答案

每次调用$时,即使结果内容相同,它也会返回不同的结果集对象.您要做的检查是:

Each time you call $, it returns a different result set object, even if the result contents are the same. The check you have to do is:

if (pauseMe.is("#leftBubble")) {

这篇关于jQuery将$ this传递给函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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