本文介绍了如何禁用 Twitter Bootstrap Modals 的转义键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在显示的模态中有一个表单.如果我专注于输入字段(与此相关的任何字段)并按 ESC 键,则该模式将被隐藏.但是,如果我不关注表单字段,则按 ESC 键不会关闭模式.怎么回事?

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 field, then pressing ESC key does not close the modal. What's going on?

我想完全禁用模态的 ESC 键功能.我试过这个:

I want to disable ESC key functionality for the modals altogether. I tried this:

$(document).on('keypress', function(e) {
  if(e.keyCode == 27) {
    e.preventDefault();
    return false;
  }
}

但这不会影响任何事情.有没有办法完全禁用模态的 ESC 键?

But this does not affect anything. Is there a way to completely disable ESC key for modals?

推荐答案

通过添加 data-keyboard="false" 解决了问题.

By adding data-keyboard="false" fixes the problem.

类似这样:<div class="modal hidefade" data-keyboard="false" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

这篇关于如何禁用 Twitter Bootstrap Modals 的转义键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:18