javascript - Catch keypress document wide and start typing in search box -
I want to capture all the key presses on my webpage so that when you start typing text, the search box (input)
jquery Can be:
var $ search = $ ("#search"); $ (Document) .on ("keydown", function (e) {if (! $ Search.is (": focus")) if (e.he! = 9 & amp; e.which! = 13) $ search Focus ();}); If the focus has already been set, then the .focus () function will not be called to set the focus on the input field. If the user pressed the tab or enter key, then the input field will not be selected!
Accessibility
If someone tries to use your mouse without a mouse (just with the keyboard), then navigate anywhere will not be able to. You may have to consider using additional techniques like HTML.
Comments
Post a Comment