How to avoid to modify the event object in this situation

后端 未结 1 1251
耶瑟儿~
耶瑟儿~ 2021-01-20 07:24

This question is related to this one Autocomplete: first item focused only when the user type on tab key.

In order to make the first item focused only when the user

1条回答
  •  别那么骄傲
    2021-01-20 07:35

    You're correct: The event will be modified an all listeners will see the modified key code.

    But the more important question is: Is this dangerous?

    To answer this, we need to know which listeners are bound to the element. Surely, all the listeners from the autocomplete plugin are designed to handle this situation. For them, this is OK.

    The trouble starts when you bind your own events to the widgets.

    A solution would be to create new events (using document.createEvent() + copying all important attributes) and send the clone to avoid modifying the original event.

    Some links:

    • Keyboard Events and Codes (shows the fields of the events as you type)
    • KeyboardEvent from the Mozilla Developer Network
    • jQuery.Event has helper code to create and work with events
    • Understanding Keyboard Event Data from Dynamic HTML: The Definitive Reference, 2E. Chapter 6: Scripting Events

    0 讨论(0)
提交回复
热议问题