Introduction to javascript events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.