In some web pages or in the pop-up layer, we generally do not want to use tab or
After the tab key is used, some problems may occur, such:
After the pop-up layer, the tab key can also be operated on the page, which leads to a script error.
So what if we want to avoid this situation?
Control by Keyboard Events
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript" src = "../javascript/jquery-1.2.6.min.js"> </script>
<Script language = "javascript" type = "text/javascript">
$ (Document). ready (function (){
$ (Document). bind ('keylow', function (event ){
If (event. keyCode = 9 ){
Document. body. focus ();
}
});
});
</Script>
The above code is familiar with that when you press the tab key, move the focus to the top of the tabindex 0 again.
At this time, we need to set the page focus for initialization at the beginning of the page.
For example, the following example is written using aspx:
<Box: Button ID = "BtnClose" Text = "Close" runat = "server" SystemIcon = "Close" TabIndex = "0" FocusOnPageLoad = "true">
</Box: Button>
In some special cases, we need to set the focus position during page loading to prevent the tabindex setting from being invalid or affected by other factors.
In this way, we can be foolproof!