How to add onkeydown to body?

后端 未结 3 1384
离开以前
离开以前 2021-01-18 07:08

In my index.html I have this code. I would need to add onkeydown event to that body in Main.onLoad().

Any idea how to do it?



        
3条回答
  •  耶瑟儿~
    2021-01-18 07:21

    You can attach listeners like this: you can pass a function or simply invoke an anonymous one in code.

    document.body.addEventListener('keydown',Main.onLoad);
    

    Seems to work on stack overflow when passed to console.

提交回复
热议问题