How to set cursor to input box in Javascript?

后端 未结 8 649
长情又很酷
长情又很酷 2020-12-13 03:42
document.getElementById(frmObj.id).value=\"\";
document.getElementById(frmObj.id).autofocus;
document.getElementById(\"errorMsg\").innerHTML = \"Only numeric value i         


        
相关标签:
8条回答
  • 2020-12-13 03:54

    In JavaScript first focus on the control and then select the control to display the cursor on texbox...

    document.getElementById(frmObj.id).focus();
    document.getElementById(frmObj.id).select();
    

    or by using jQuery

    $("#textboxID").focus();
    
    0 讨论(0)
  • 2020-12-13 03:55

    In my experience

    document.getElementById(frmObj.id).focus();

    is good on a browser running on a PC. But on mobile if you want the keyboard to show up so the user can input directly then you also need:

    document.getElementById(frmObj.id).select();

    0 讨论(0)
提交回复
热议问题