Ejemplo 1: clic del gatillo js
var element = document.getElementById('element');
element.click();
Ejemplo 2: javascript enlazar la tecla al botón
//https://stackoverflow.com/questions/6542413/bind-enter-key-to-specific-button-on-page
//upvote them on stackoverflow
//jquery------------------------------------------------------
//answer by Chris Laplante
$(document).keypress(function(e){
if (e.which == 13){
$("#button").click();
}
});
//pure javascript--------------------------------------------
//answer by Alexander Kim
window.addEventListener('keyup', function(event) {
if (event.keyCode === 13) {
alert('enter was pressed!');
}
});
//https://www.w3schools.com/howto/howto_js_trigger_button_enter.asp
// 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();
}
});
Ejemplo 3: clic del gatillo js
<a href="#" target="_blank" onclick="javascript:Test("Test");">MSDN</a>
Ejemplo 4: clic del gatillo js
<form>
<input type="checkbox" id="myCheck" onmouseover="myFunction()" onclick="alert('click event occurred')">
</form>
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)