use*_*627 19 javascript focus html-input
我目前在我的aspx中有一个文本框:
<input type="text" id="myTextbox" value="" />
Run Code Online (Sandbox Code Playgroud)
我想知道每次调用JavaScript方法时是否可以设置焦点(将光标放在该文本框中).我希望它能按照以下方式工作:
function setFocus() {
document.getElementById("myTextbox").Focus();
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
小智 28
调用小写.focus()函数:
function setFocus() {
document.getElementById("myTextbox").focus();
}
Run Code Online (Sandbox Code Playgroud)