在 Jquery 中的悬停函数中传递变量
我正在为按钮执行一个非常简单的悬停功能,我需要传递一个变量。我可以在悬停的第一个状态下使用该变量,但不能在第二个状态下使用该变量。这是否与变量是本地定义的并且在第二个函数中不可用这一事实有关?
这是代码:
$('#'+'[id^="world_map"]').hover(function() {
var that2 = this.id;
$('#' +that2+ '_thumbnail_container').animate({"opacity" : 1}, 150, function() { });
$('#' +that2+ '_thumbnail_container').css('visibility','visible');
},
function() {
$('#' +that2+ '_thumbnail_container').animate({"opacity" : 0}, 150, function() { });
$('#' +that2+ '_thumbnail_container').css('visibility','hidden');
});
谢谢!
I'm doing a very simple hover function for a button and I need to pas down a variable. I can use the variable in the first state of the hover but not in the second. Does it have something to do with the fact that the variable is defined locally and not available in within that second function?
Here's the code:
$('#'+'[id^="world_map"]').hover(function() {
var that2 = this.id;
$('#' +that2+ '_thumbnail_container').animate({"opacity" : 1}, 150, function() { });
$('#' +that2+ '_thumbnail_container').css('visibility','visible');
},
function() {
$('#' +that2+ '_thumbnail_container').animate({"opacity" : 0}, 150, function() { });
$('#' +that2+ '_thumbnail_container').css('visibility','hidden');
});
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,这是因为变量
that2
是在第一个函数的范围内定义的。但是,值 (this.id
) 本身在这两种方法中都可用。You're right, it is because the variable
that2
is defined in the scope of the first function. However, the value (this.id
) itself is available in both methods.