JavaScript events
1, <button id= "btn1" onclick="document.getElementById (" Btn1 "). Innertext=date ();" > What's the time now? </button>
2, <button onclick= "this.innerHTML= Date () "> What's the time now? </button>
3, <button id= "btn1 " onclick= "display_type () " > What time Is it now? </button>
< Script>
function Display_type () {
document.getElementById ("Btn1"). Innertext=date ();
</script>
Common HTML events for JavaScript
The following is a list of some common HTML events:
Events |
Description |
OnChange |
HTML element Changes |
OnClick |
User clicks on HTML element |
onmouseover |
The user moves the mouse over an HTML element |
onmouseout |
The user moves the mouse away from an HTML element |
OnKeyDown |
The user presses the keyboard key |
OnLoad |
The browser has finished loading the page
|
JavaScript scopes
Events can be used to process form validation, user input, user behavior, and browser actions:
- Trigger event when page loads
- Trigger event when page closes
- The user clicks the button to perform the action
- Verifying the legality of user input
- Wait a minute...
You can use several methods to execute JavaScript event code:
- HTML Event Properties can execute JavaScript code directly
- HTML Event Properties can call JavaScript functions
- You can specify your own event handlers for HTML elements
- You can stop the event from happening.
- Wait a minute...
JavaScript Daily Learning 4