Setting focus to a textbox when a function is called

前端 未结 2 1478
一整个雨季
一整个雨季 2020-12-18 19:59

I currently have a textbox in my aspx:

 

I was wondering if I could set the focus

相关标签:
2条回答
  • 2020-12-18 20:22

    Try this:

    function setFocus(id) {
        document.getElementById(id).focus();
    

    }

    In this way, your function becomes reusable. Just pass the ID of the html element to be given the focus when you call the function.

    M.

    0 讨论(0)
  • 2020-12-18 20:25

    Invoke the lowercase .focus() function:

    function setFocus() {
        document.getElementById("myTextbox").focus();
    }
    
    0 讨论(0)
提交回复
热议问题