简体   繁体   English

禁用对模态后面元素的所有按键

[英]Disable all keypresses to elements behind modal

In either Javascript or HTML, is there a way to disable all user input except for a selection of keyboard presses?在 Javascript 或 HTML 中,有没有办法禁用除键盘按下选择之外的所有用户输入? For example, if I trigger an error that shows a popup error message, is there a way to block any other user input into the DOM in the backround until the user has dismissed the popup using the Enter key?例如,如果我触发显示弹出错误消息的错误,是否有办法阻止任何其他用户在后台向 DOM 输入,直到用户使用 Enter 键关闭弹出窗口?

Thank you all in advance!谢谢大家!

If I understand you correctly, you might want to disable keyboard and mouse activity beyond the modal when opening like with this related question .如果我对您的理解正确,您可能希望在打开时禁用超出模式的键盘和鼠标活动,就像这个相关问题一样。 Here is the summary of the options included:以下是包含的选项的摘要:

If you opening the modal by js use:如果您通过 js 打开模态,请使用:

$('#myModal').modal({backdrop: 'static', keyboard: false})  

If you are using data attributes, use:如果您使用的是数据属性,请使用:

 <button data-target="#myModal" data-toggle="modal" data-backdrop="static" data-keyboard="false">
    Launch demo modal
 </button>`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM