Javascript jQuery clearInterval不工作

Javascript jQuery clearInterval不工作,javascript,jquery,Javascript,Jquery,我有以下悬停功能 function tt_attachToBase(){ jQuery.each(bases, function(index,base){ jQuery(base).hover(function() { jQuery(base).showTipTimer = setInterval( function(){tt_locateBase(base);} ,

我有以下悬停功能

function tt_attachToBase(){
        jQuery.each(bases,
            function(index,base){

                jQuery(base).hover(function() {  
                         jQuery(base).showTipTimer = setInterval( function(){tt_locateBase(base);} , 3000 ); 
                             },  
                            function() {  
                                clearInterval(jQuery(base).showTipTimer);
                                tt_hideTip();
                                    }

                    }); 
            }

        );
在tt_locateBase()中,我也像这样清除间隔

tt_locateBase(base){
clearInterval(jQuery(base).showTipTimer);
//code to sidplay tooltip
}

工具提示确实会在间隔后显示,但它看起来的间隔永远不会被清除,因为工具提示会在基础上重复出现。我做错了什么

将属性设置为
jQuery(base)
的返回值只会影响该特定对象。如果再次获取
jQuery(base)
,它将不会携带该属性

您当前正在执行的操作相当于以下代码:

function return_something() {
    return ['foo', 'bar'];
}

var first_fetch = return_something();
// => ['foo', 'bar']
first_fetch.push('baz'); // => ['foo', 'bar', 'baz']

var second_fetch = return_something(); // => ['foo, 'bar']
解决方案 也许把它当作附件吧?这样,它将影响DOM中的实际对象,而jQuery对象将在后续获取中携带该数据值

jQuery(base).data('showTipTimer', 
  setInterval(function(){tt_locateBase(base);} , 3000));
然后用以下方法清除:

clearInterval(jQuery(base).data('showTipTimer'));
你试过这个吗:

   jQuery(base).hover(function() {  
         var idInterval = setInterval( function(){tt_locateBase(base, idInterval);} , 3000 ); 
                         },  
然后

tt_locateBase(base, i){
clearInterval(i);
//code to sidplay tooltip
}

什么值有jQuery(base).showTipTimer在tt_locateBase中?很抱歉,我从悬停函数传递它base,我编辑了上面的代码Firebug在jQuery(base).data('showTipTimer',setInterval(function(){tt_locateBase(base);},3000)上的参数“缺失”错误;添加了一对额外的()setinterval和3000左右也不能解决问题。抱歉,我忘记了结尾处的括号。现在已修复。这可能会起作用,但页面上有多个工具提示,因此我宁愿在每个基上附加一个单独的计时器