Is there something like $('a#link_id').activate() in jQuery?
When I bind a function to a link with $('a#link_id').click()
and then I click the link, it runs the function and everything it's okay, but when I "activate" the button in another way (i. e. focusing with tab and then pressing barspace) it just doesn't works.
It happens the same with $('select#dropbox_id').change()
: It works when I change it with the mouse but not with the direction arrows. Is there a way for 开发者_C百科achieving this whitout having to rebind manually with $.keyup()
? I don't know, maybe I'm just missing an event.
You don't need any type of those events.
For click event, it occurs when you click an element with mouse or with space bar. If your click event isn't firing when you use space bar, probably you have an error somewhere else.
When you change a drop down box, then and only then the change event fires. When you use the arrow key to change the drop down box's selected value, that value isn't immediately selected, only when the focus of the control is lost that value is assigned to be its control's selected value, and as a result, the change event fires.
If you want to achieve the event firing mechanism with the arrow keys, then you will have to use the keyup/keydown event, there is no other way(as far as I know). Also, you may detect the key that was pressed to determine whether it is one of the direction arrow that is pressed.
If you still need any help, you may include the code with your question.
I hope this helps.
I guess you are missing the focus
or focusin
event. On select
elements, there is no native event which fires when you scroll down the list by keyboard input for instance. focus
and focusin
will fire once the element
gains the focus.
You can't bind such an event type to the options
, at least not crossbrowser. So if you really want to catch that, you have to bind a keydown
or keyup
event to the parent select
element.
精彩评论