English 中文(简体)
j Query - 越狱,如果超支,就关闭窗口
原标题:jQuery - On escape, close window if overlay not open

当敲响越狱钥匙时,我想关闭一个儿童窗口,但首先检查公开的超支。 如果超支已经开张,越狱钥匙被压倒,我只想结束超支。 如果用户报界再次逃跑,我想关闭儿童窗口。

因此,我首先需要检查超支是否开放。 我的所有超支都有以下类别:.simpleOverlay和与.closeOverlayBtn相近的纽子,因此,我认为,在关闭窗口之前,如果该类别有重点,就可发挥职能:

if (e.keyCode == 27) { // "Esc" Key
   if ( $( .simpleOverlay ).is( :focus ) ) {
       $( .closeOverlayBtn ).trigger( click );
   }
   else {
       window.close();
   }    
   return(false);
}

但是,这并没有发生! 如果我把<代码>.trigger项目改为alert(),那么当超支关闭、开放、不好时,我就会得到警示。

这样做的正确途径,还是我完全没有东西?

最佳回答

为此:

if (e.keyCode == 27) { // "Esc" Key

   if ( $( .simpleOverlay ).is( :visible ) ) {
       $( .closeOverlayBtn ).click();
   }
   else {
       window.close();
   }    
   return(false);
}
问题回答

Use modern JS

if (e.key === "Escape") {
   if ($( .simpleOverlay ).is( :visible )) {
       $( .closeOverlayBtn ).click();
   }
   else {
       window.close();
   }    
   return false;
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签