Come fare per - Pulsante di attivazione Fare clic su Invio
Attiva un clic del pulsante sulla tastiera "invio" con JavaScript.
Attiva un pulsante Fare clic su Invio
Premere il tasto "Invio" all'interno del campo di immissione per attivare il pulsante:
Esempio
// 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();
}
});
Suggerimento: scopri di più sulla proprietà event.keyCode nel nostro JavaScript Reference.