如何通过单击 html 按钮将光标移动到输入文本框中?

use*_*033 5 html javascript dom

嗨,谁能告诉我如何通过单击 html 按钮将光标移动到输入文本框中?

عثم*_*غني 1

您只需使用jQuery以下方法即可做到这一点:

然后包含jqueryHTML HEAD部分中

$( "#button" ).click(function() {
$( "#targetinput" ).focus();
});
Run Code Online (Sandbox Code Playgroud)

或者没有 jquery 你可以使用

getElementByID("targetinput").focus();
Run Code Online (Sandbox Code Playgroud)