Javascript: focus focus in dialog

I have a popup dialog box (div with high z-index) that contains some input elements. Although this dialog box is open, I would like the tab and shift-tab to include only loops between the elements in this dialog box. How can i do this?

+3
source share
2 answers

You can use the tabIndex property and set it to -1 for all elements that you do not want to cycle through the tab.

<input type="text" id="no-tab-cycle" tabIndex="-1"/>

Of course, you will need to control this behavior with some smart selectors using jQuery or something like that, but it depends on how complex your forms are.

Maybe someone has a better answer.

jQuery , my-popup-dialog, , ,

$('input, textarea, select').each(function(index) {
    $(this).attr('tabIndex', '-1');
});

$('#my-popup-dialog input, #my-popup-dialog textarea, #my-popup-dialog select').each(function(index) {
    $(this).removeAttr('tabIndex');
});
+3

, ( ) . , :

  • onfocus ( ), , , currentFocus.

  • onblur , , previousFocus.

  • onfocus, , : previousFocus - , currentFocus - , - . , -tabbing .

0

Source: https://habr.com/ru/post/1760163/


All Articles