How to set the focus on a hidden textbox field using JavaScript?

前端 未结 4 1887
自闭症患者
自闭症患者 2020-12-16 10:13

How can I set the focus on a hidden textbox element?

I tried this:

document.getElementById(\"         


        
4条回答
  •  无人及你
    2020-12-16 11:12

    If you really need to do this, make the box transparent, not hidden:

    opacity:0;
    filter:alpha(opacity=0);
    

    Alternatively, if you want to ensure that the user doesn't accidentally click it, just place the input inside a div with

    width: 0;
    overflow: hidden;
    

    However, there is most certainly a better way to do what you want, maybe using keydown/keypress events.

提交回复
热议问题