控制台在最后没有检测到overExpand
为真。难道我做错了什么?为什么不检测布尔变量?
var transLayer = $('.transparentBg');
var overExpand = false;
var overUl = false;
$(transLayer).hide();
console.log('transLayer hide'); // this is being logged
$('#header .nav .wrapper > ul > li.expand').hover(function(){
overExpand = true;
console.log(overExpand);// this works = true
}, function(){
overUl = true;
});
console.log(overExpand); // this shows false
我更新了我的问题中的一些代码。是的你是对的,添加'console.log'确实在悬停事件中起作用。但是有没有办法从事件外部检测布尔变化? – muudless 2012-08-08 01:38:24
@ muudless - 我原来的答案仍然适用。由于在事件被触发之前该值没有被设置,所以在添加处理程序之后但在处理程序触发之前执行的代码仍然会看到原始值。 – 2012-08-08 01:47:54
谢谢,我现在明白了。我想我只需要在调用悬停事件时触发另一个函数。 – muudless 2012-08-08 01:55:47