Events in JavaScript (JS)?

2026-10-11来源 dev.to JavaScriptEnglish

In JavaScript, an event is an action that happens in a web page. JavaScript can detect that action and execute code in response.

For example:

  • Clicking a button
  • Typing in an input field
  • Moving the mouse
  • Submitting a form
  • Loading a webpage
  • Pressing a keyboard key

Common JavaScript Events

Event Description

click - When an element is clicked
dblclick - When an element is double-clicked
mouseover - When the mouse moves over an element
mouseout - When the mouse leaves an element
keydown - When a keyboard key is pressed
keyup - When a keyboard key is released
input - When an input value changes
change - When a value is changed and committed
submit - When a form is submitted
load - When a page or resource finishes loading.

Example:

<!DOCTYPE html>


JavaScript Events

<h2 id="heading">Hello, JavaScript!</h2> <button>Click Me</button> <script> function showMessage() { document.getElementById("heading").innerText = "Button Clicked Successfully!"; } </script> 

原文:https://www.a8q9.cn/en/article/events-in-javascript-js-a22fb4.html

相关文章