使用 jquery 绑定 mouseleave 上的 settimeout
我正在使用类和对象以及一点 jquery 使用 javascript 构建一个幻灯片菜单,作为我更深入地学习 javascript 的努力的一部分。 一切都很顺利,直到我想将 mouseleave 绑定到菜单的启动器上。 所以这是我的代码块
var el;
function generate(obj){
return function(){obj.slidein();}
}
function slider(arg1,arg2){
...//Some junk
el=this;
for(i=0;i<this.nsubs;i++){ ...
$("#"+this.id+i).bind('mouseleave',function(){setTimeout("generate(el)",500)});
}
...
}
好吧,我在 Firefox 错误控制台上没有收到错误,但不知何故,当鼠标离开有问题的元素时,我想要附加到 mouseleave 的 slipin() 函数没有被调用。
有人可以解释我在这里做错了什么吗?
I was building a slide-menu with javascript using classes and objects and a little bit of jquery as part of my efforts to learn javascript more deeply.
Everything went right until I wanted to bind a mouseleave to the initiator of my menu.
So here's my code block
var el;
function generate(obj){
return function(){obj.slidein();}
}
function slider(arg1,arg2){
...//Some junk
el=this;
for(i=0;i<this.nsubs;i++){ ...
$("#"+this.id+i).bind('mouseleave',function(){setTimeout("generate(el)",500)});
}
...
}
Well, I get no error on firefox error console but somehow the slidein() function which I want to be attached to the mouseleave is not being called when mouse leaves the element in question.
Can Someone explain what I am doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将函数而不是字符串传递给 setTimeout:
Try passing a function rather than a string to setTimeout:
好吧,我自己解决了,我真正需要的是一个返回带有 'setTimeout(generate(ObjPassedToClosure))' 的函数的闭包
Alright, I sorted it out on my own, what I actually needed was a closure that returns a function with 'setTimeout(generate(ObjPassedToClosure))'