Autofocus to a div so we can use arrow keys to scroll without having to click first

后端 未结 4 1518
你的背包
你的背包 2021-01-06 06:57

I have a page with a few

containers.

How to give focus to one of them on page load, so that the user can use arrow keys to scroll (or even

4条回答
  •  盖世英雄少女心
    2021-01-06 07:14

    Focus events are used for input elements. Use click event instead:

    document.querySelector('#main').click();
    

    Also, make use of tabindex to bind keyboard events on non-input elements:

    main content

提交回复
热议问题