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();" />