JavaScript HTML DOM events
Event
Event is a certain action performed by the user or the browser itself, such as click, load and mouseover are both event names.
Events are the bridge between javaScript and DOM.
If you trigger it, I will execute it - when the event occurs, its handler function is called to execute the corresponding JavaScript code to give a response.
Typical examples include: the load event is triggered when the page is loaded; the click event is triggered when the user clicks on an element.
Reacting to events
We can execute JavaScript when an event occurs, such as when the user clicks on an HTML element.
To execute code when the user clicks an element, add JavaScript code to an HTML event attribute:
onclick=JavaScript
HTML Examples of events:
When the user clicks the mouse
When the web page has loaded
When the image has loaded
When the mouse moves over the element
When the input field is changed
When the HTML form is submitted
When the user triggers a keypress
php中文网(php.cn) 点击!
To assign an event to an HTML element, you Event properties can be used.
php中文网(php.cn)
HTML DOM allows you to use JavaScript to assign events to HTML elements:
php中文网(php.cn)
onchange event The onchange event is often used in conjunction with validation of input fields.php中文网(php.cn)
php中文网(php.cn) 输入你的名字:当你离开输入框后,将小写字母转为大写字母。
onmouseover and onmouseout events
The onmouseover and onmouseout events can be used to trigger functions when the user's mouse moves over or out of an HTML element.
php中文网(php.cn) Mouse Over Me
onmousedown, onmouseup and onclick events
onmousedown, onmouseup and onclick make up all parts of the mouse click event. First when the mouse button is clicked, the onmousedown event is fired, when the mouse button is released, the onmouseup event is fired, and finally, when the mouse click is completed, the onclick event is fired.
php中文网(php.cn)
Other events:
onmousedown and onmouseup
Change an image when the user presses the mouse button.
onload
When the page completes loading, a prompt box is displayed.
onfocus
Changes the background color of an input field when it gets focus.
Mouse events
When the pointer moves over the element, its color changes; when the pointer moves out of the text, it changes its color again.