I have one text input and one button (see below). 我有一个文本输入和一个按钮(见下文)。 How can I use JavaScript to trigger the button's click event when the Enter key is pressed inside the text box? 当在文本框中按下Enter键时,如何使用JavaScript 触发按钮的click事件 ? ide
There is already a different submit button on my current page, so I can't simply make the button a submit button. 当前页面上已经有一个不一样的“提交”按钮,所以我不能简单地将该按钮设为“提交”按钮。 And, I only want the Enter key to click this specific button if it is pressed from within this one text box, nothing else. 并且,若是只从一个文本框中按下该按钮,我只但愿按Enter键便可单击该特定按钮,没有别的。 this
<input type="text" id="txtSearch" /> <input type="button" id="btnSearch" value="Search" onclick="doSomething();" />