![](/img/trans.png)
[英]How to close a custom drop down menu when user clicks somewhere else on the page
[英]How to close GreyBox on pressing escape or if a user clicks somewhere else on the page?
我正在使用GreyBox在同一窗口中打开新的HTML页面。 它工作正常,但现在我希望在按下转义键或用户单击页面其他位置时将其关闭。 我怎样才能做到这一点?
编辑: - -
document.onkeypress = function (event) {
if (event == undefined) { event = window.event; }
if (event.keyCode == 27) {
AJS.AEV(document,"keypress",GB_hide);
}
}
我用了它,它在mozilla上运行良好,但在safari或chrome上却没有。
这成功了。
document.onkeypress = function noNumbers2(e){
e = e || window.event;
var keynum = e.keyCode || e.which;
if(keynum == 27){
AJS.AEV(document,"keypress",GB_hide);
}
}
使用jquery可以做到这一点。 对我来说很好
单击退出按钮
$(document).keyup(function(e) {
if (e.keyCode == 27) { parent.GB_hide(); } // esc
});
在外窗点击
$(document).on('click','#GB_overlay', function(e) {
parent.GB_hide();
});
也许这对您有帮助?
window.document.onkeydown = function(evt) {
if (evt.keyCode == 27) {
if (alert.open) {
alert.close();
}
}
}
而不是使用谷歌给你想要重定向的页面网址
OnClientClick =“ top.window.location.href ='http://localhost/yourpagename.aspx'; parent.parent.GB_hide();”
是在单击按钮时关闭并重定向jquery灰色框的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.