我发现当按下 ESC 按钮时从 keyDown 事件处理程序调用 location.reload() 调用时,它不会执行任何操作。有人知道如何重新加载页面的解决方法吗?我还发现http://bugs.jqueryui.com/ticket/4922 http://bugs.jqueryui.com/ticket/4922看起来这个问题已经解决了。
这是代码示例。
订阅事件:
jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
closeVideoPopup();
}
});
和 closeVideoPopup() 方法:
function closeVideoPopup() {
jQuery('#fade, .window_container').fadeOut(function(){
jQuery('#fade, a.close').remove();
});
jQuery('ul.tabs').css('z-index', '99');
jQuery('div.framing_slider').css('z-index', '9999');
location.reload();
return false;
}
请注意,此代码在除 FF 之外的所有浏览器中都能完美运行.
That's because the Esc key stops the refresh immediately after you fire it in Firefox.
Use a setTimeout
so the location.reload()
将在事件已经完成冒泡后执行。
jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
setTimeout(closeVideoPopup, 0);
}
});
Fiddle http://jsfiddle.net/TKmS5/5/
Or better, just call event.preventDefault() http://api.jquery.com/event.preventDefault/ so the Esc key won't cancel the page reload:
jQuery(document).keydown(function (event) {
if (event.keyCode == 27) {
event.preventDefault();
closeVideoPopup();
}
});
Fiddle http://jsfiddle.net/TKmS5/6/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)