Javascript events are undoubtedly one of the typical features of the javascript language. We will discuss them one by one and give examples.
1. onabort event, onerror event, onload event, and onunload Event
The first one is used for the img label, and the last two are used for loading pages and images, which are events triggered when loading fails and loading is successful, respectively.
If the image loading is interrupted, a change event is triggered.
Code:
/></body>
2. onblur events and onfocus events
Blur indicates fuzzy meaning. This event is triggered when the page element loses focus. Most page elements can be used to trigger this event. Some people may not understand the meaning of the loss of focus. In fact, when you press the mouse or the tab key on the keyboard, the focus is transferred to another object or page. On the contrary, the focus is concentrated, that is, the event triggered when the element obtains the user focus.
Code:
<Html>
<Head>
<Meta charset = "Utf-8">
<Script type = "text/javascript">
Function upperCase ()
{
Var x = document. getElementById ("fname"). value
Document. getElementById ("fname"). value = x. toUpperCase ()
}
</Script>
</Head>
<Body>
Enter your name:
<Input type = "text" id = "fname" onblur = "upperCase ()"/>
</Body>
</Html>
3. onchange event
This event is triggered when the content of the input field changes.
<Html> onchange="upperCase(this.id)"/> </Body>
4. onclick and ondbclick
It indicates the event triggered when you click or double-click an element.
<Html> <body> Field1: <input type = "text" id = "field1" value = "Hello World! "> <Br/> Field2: <input type =" text "id =" field2 "> <br/> double-click the following button, copy the content of Field1 to Field2: <br/> <buttonondblclick="document.getElementById('field2').value=document.getElementById('field1').value"> Copy Text </button> </body>
5. Events related to keyboard buttons are onkeydown events, onkeyup events, and onkeypress events.
It means that when the button is pressed, the button is up, and the button is pressed and released.
Ie is window. event, and others are event. which. chrome. Both are supported.
e.keyCode }else if(e.which) // Netscape/Firefox/Opera { keynum = e.which }keychar = String.fromCharCode(keynum)numcheck = /\d/return !numcheck.test(keychar)}</script><form><input type="text" onkeydown="return noNumbers(event)" /></form>
6. onmousedown event, onmousemove event, onmouseout event, onmouseover event, onmouseup event, and mouse-related event
As the name implies
7. onsubmit event
Event where the submit button is pressed