“On ENTER Tekan Tombol” Kode Jawaban

Klik Tombol Saat Tekan Enter JavaScript

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();
  }
});
Maeron Reyes

Tekan tombol di Enter

searchInput.onkeyup = function (e) {
    if (e.key === 'Enter') {
        searchBtn.click();
    }
}
Arno Deceuninck

On ENTER Tekan Tombol

<input onkeyup="if(event.keyCode===13){submit.click()}"><button id="submit">submit</button>
FrostyAnimations126

Tombol OnClick Masukkan Kunci

$("#id_of_textbox").keyup(function(event) {
    if (event.keyCode === 13) {
        $("#id_of_button").click();
    }
});
Ashamed Alpaca

JavaScript mengikat tombol ke tombol

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

Jawaban yang mirip dengan “On ENTER Tekan Tombol”

Pertanyaan yang mirip dengan “On ENTER Tekan Tombol”

Lebih banyak jawaban terkait untuk “On ENTER Tekan Tombol” di HTML

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya