简体   繁体   中英

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? 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?

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:

$('#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>`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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