How can I get keydown events on a div in chrome?

后端 未结 1 436
迷失自我
迷失自我 2021-02-08 15:38

I\'d like to get keydown events on a div. I use JQuery keydown. Pretty simple.

However, it does not work on chrome. For this to work on chrome, I have to set tabindex =

相关标签:
1条回答
  • 2021-02-08 16:38

    Keydown event is only sent to the HTML element that has the focus. Focusable elements vary between browsers, but elements of which tabindex property is set can always get focus in most browsers.

    You have already set tabindex for div element so that it is focusable and can receive keyboard event. Your problem is the default outline of currently focused element on Google Chrome.

    To change the outline (the "ugly orange border" as you mentioned), use pseudo CSS class :focus and CSS property outline. The following example will remove outline from all elements when they have focus:

    *:focus
    {
        outline: none;
    }
    

    Hope this help.

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