javascript - Can you bind an event to access keys? -
as know, in html there's accesskey
attribute lets assign key elements can trigger/focus them directly keyboard, without having tab them first.
now wondering, if can bind js event exact... event, or have go old-fashioned way , listen onkeypress
(for example) , check key combination?
the latter kind of defeat purpose, since browsers have different key combinations trigger access keys.
my idea behind assigning access key (mega menu) navigation, unfold , focus it, can tab through links. way can put navigation @ end of html, users don't have tab through hundreds of links (exaggeration) before can reach links in actual content area.
there no such event, instance no onaccesskey event have hook 1 of onkey* events.
however accesskey trigger activation events elements when accesskey used (tested chrome , firefox). can use events if user clicked,focused,changed part of ui.
- display elements, i.e. div,span, etc:
- onclick
- input elements, i.e. text,textarea:
- onfocus, if not focused
- onclick in browsers
- input elements, i.e. radio,checkbox:
- onfocus, if not focused
- onclick
- onchange, if not checked
- select elements:
- onfocus, if not focused
- onclick, if not selected
- select element options (triggered on select element):
- onfocus, if select box not focused
- onclick, if select box not selected
- onchange, if option not selected
an example of using open menu
html
<div id="menu"> <div id="menubtn" accesskey="r">menu</div> <ul> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> </div>
js
jquery("#menubtn").click(function(){ jquery(this).next().toggle(); });
Comments
Post a Comment