use tabindex to bind keyboard event for DIV

W3C 的标准

HTML 4.01 only defines the tabindex attribute for a, area, button, input, object, select, and textarea, and limits its value to the range between 0 and 32767.

The objective of this technique is to demonstrate how to provide keyboard access to a user interface control that is implemented by actions to static HTML elements such as div or span. This technique ensures that the element is focusable by setting the tabindex attribute, and it ensures that the action can be triggered from the keyboard by providing an onkeyup or onkeypress handler in addition to an onclick handler.

When the tabindex attribute has the value 0, the element can be focused via the keyboard and is included in the tab order of the document. When the tabindex attribute has the value -1, the element cannot be tabbed to, but focus can be set programmatically, using element.focus().

MDN 这里就写的不明不白了。.


JS Bin on