How do you clear the focus in javascript?

前端 未结 7 1822
遥遥无期
遥遥无期 2020-11-28 04:45

I know this shouldn\'t be that hard, but I couldn\'t find the answer on Google.

I want to execute a piece of javascript that will clear the focus from whatever eleme

7条回答
  •  一个人的身影
    2020-11-28 05:10

    You can call window.focus();

    but moving or losing the focus is bound to interfere with anyone using the tab key to get around the page.

    you could listen for keycode 13, and forego the effect if the tab key is pressed.

提交回复
热议问题