Как сделать - Кнопка триггера Нажмите Enter
Запустите нажатие кнопки на клавиатуре «ввод» с помощью JavaScript.
Активировать кнопку Нажмите Enter
Нажмите клавишу «Ввод» внутри поля ввода, чтобы активировать кнопку:
Пример
// Get the input field
var input = document.getElementById("myInput");
// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup",
function(event) {
// Number 13 is the "Enter" key on the keyboard
if (event.keyCode ===
13) {
// Cancel the default action, if needed
event.preventDefault();
// Trigger the button element with a click
document.getElementById("myBtn").click();
}
});
Совет: Узнайте больше о свойстве event.keyCode в нашем Справочнике по JavaScript.