Event handling
1. Event source: any HTML element (node), body, div, button
2. Event: Your operation
mouse:
click
dblick double-click
oncontextmenu Text menu
The code copy is as follows:
<body oncontextmenu="return false">//Prohibit the right-click program
mouseover put
mouseout
mousedown
mouseup lift
mousemove mouse
keyboard:
keypress keyboard event
keyup lift
keydown
document:
load load
onload is an event that fires after the page loads
unload close
Before the protectedunload is closed
Form:
focus event
blur loses focus
Submit Submit Event
Change Change Event
other:
scroll
selectstart Select event
3. Event handler
The first type:
Format: <tag on event="event handler" />
Example:
The code copy is as follows:
<script>
function show(){
var one=document.getElementById("one");
alert(one.innerText);
}
show();
</script>
<body>
<div id="one">
wwwwwwwwwwwwwwwwwwwwwwww
</div>
<input type="button" onclick="show()" value="show">
The second type:
Directly handler in javascript object.on
The code copy is as follows:
<div id="two">
Hello, Wulin.com//www.VeVB.COM
</div>
<script>
var one=document.getElementById("two");
one.onclick=function(){
this.style.backgroundColor="red";
}
</script>
The third type:
Basically no one uses it
The code copy is as follows:
<script for="Event Source ID" event="Event">Event Handler</script>
<div id="th">
Hello, Wulin.com//www.VeVB.COM
</div>
<script for="th" event="onclick">
var one=document.getElementById("th");
one.style.backgroundColor="red";
</script>
Have you understood the JavaScript incident handling? Leave me a message if you have any questions.