按ESC按钮禁用进一步使用<a> tag

时间:2017-10-11 09:21:07

标签: javascript jquery html

I am using the following code for closing the popup using ESC Key. But after ESC button is pressed the link used to create pop up becomes disabled.

    $(document).keydown(function(e) {
      if (e.keyCode == 27) { 
       $(".overlay").hide();
    }   
    });

This is the HTML code

<a href="#popup1
 <li>bla bla</li>
</a>

<div id="popup1" class="overlay">
 <div class="popup">
  <a class="close" href="#">&times;</a>
    <div class="content">
     <p>Hello</p>
    </div>
 </div>
</div>

1 个答案:

答案 0 :(得分:1)

希望这会对你有所帮助。

$(document).keydown(function(e) {
    if (e.keyCode == 27) { 
       $(".overlay").hide();
    }   
});
$("your-a-tag-id-or-class").click(function(e) {
    e.preventDefault();
    $(".overlay").show();  
});