How to - ट्रिगर बटन एंटर पर क्लिक करें
एक बटन को ट्रिगर करें जावास्क्रिप्ट के साथ कीबोर्ड "एंटर" पर क्लिक करें।
एक बटन ट्रिगर करें एंटर पर क्लिक करें
बटन को ट्रिगर करने के लिए इनपुट फ़ील्ड के अंदर "एंटर" कुंजी दबाएं:
उदाहरण
// 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 प्रॉपर्टी के बारे में और जानें ।