How to disable Escape Key for Twitter Bootstrap Modals?

后端 未结 7 942
执念已碎
执念已碎 2020-12-13 17:44

In a shown modal there is a form. If I focus on an input field (any field for that matter) and press ESC key, that modal is hidden. However, if I don\'t focus on a form fiel

7条回答
  •  余生分开走
    2020-12-13 18:04

    You can target that specific input by adding an ID to it and simply removing the keydown event for enter like so:

    JS

    $(document).ready(function() {
      $('form input').keydown(function(event){
        if(event.keyCode == 13) {
          event.preventDefault();
          return false;
        }
      });
    });
    

    This example works with the Enter Key.

提交回复
热议问题