i have a form. which includes menubar, corporation icon, some links, and 10 inp开发者_C百科ut[type='text']. i have writen tabindex attribute only for 5 inputs. because i want to make so that only this five input can be focused. how i can do it?
Approach 1: Harmful with relatively weak browser support (it depends on the HTML5 draft)
Set a negative tabindex value on every element you do not wish to get the focus.
This will render it impossible for some users (especially screen reader users who have a higher portion of non-mouse users among them) to access those elements of the page.
Approach 2: Equally harmful but with relatively high browser support.
Bind, using JavaScript, an onfocus
event handler to every element that you don't want to receive the focus. Have it call the focus()
method of the first form control.
Doing either of these is a user-hostile act. Don't do it.
tabindex
sets the indexing order of items, but it does not set a limit on which elements can be focused.
You should be able to achieve what you want by giving the last input the following JavaScript:
<input onblur="$('#firstitem').focus();">
or alternatively, in the ready()
block
$("#lastitem").blur(function() { $('#firstitem').focus(); })
keep in mind though that with that, you are taking away the user's ability to navigate the page using a keyboard.
精彩评论