Html input, always in focus

后端 未结 4 1595
梦谈多话
梦谈多话 2021-01-11 19:14

How can I keep the html input always in focus? Using the autofocus attribute when creating the element helps to focus at pageload, but it does not keep the focu

4条回答
  •  -上瘾入骨i
    2021-01-11 19:45

    Try this:

    
     
    

    Basically, you add a blur event (which occurs whenever the input loses focus), and in the blur event, you focus on the input. In addition, you add the autofocus attribute to start off focused as well.

    P.S. If you are planning to use this for a website for actual people to use, from a user interface perspective, this is probably not a great idea.

提交回复
热议问题