JavaScript event concepts and monitoring events

Source: Internet
Author: User

1, the concept of the event:

JavaScript gives us the ability to create dynamic pages, and every element in the Web page can produce certain events that trigger JavaScript functions. We can think of an event as a behavior that can be detected by JavaScript.

2. Event Flow:

The event flow is mainly divided into bubble type event and capture type event. Internet Explorer currently supports only bubbling events, and browsers that support standard DOM, such as Firefox, Chrome, and so on, are supported.

3. Use the return value to change the default behavior of HTML elements:

Most HTML elements contain their own default behavior, such as hyperlinks, submit buttons, and so on. We can block its default behavior by adding "return false" to the binding event.

4, the Universal Event monitoring method:

(1) Binding HTML element attributes:

<input type= "button" value= "ClickMe" onclick= "Check (this)" >

(2) Binding DOM Object properties:

document.getElementById ("xxx"). Onclick=test;

<!DOCTYPE HTML><HTMLLang= "en">    <Head>        <MetaCharSet= "Utf-8">        <title>JavaScript two universal ways to bind events</title>        <Scripttype= "Text/javascript">            functiontest1 () {alert ("Binding HTML element Properties"); }            functiontest2 () {alert ("binding DOM Object Properties"); }        </Script>    </Head>    <Body>        <ahref= "Https://www.baidu.com"onclick= "return false">Baidu</a>        <!--hyperlinks have their own default behavior, which is to jump to the page when clicked. If you want to remove the default behavior, you can bind an onclick event, onclick= "return false". This will not jump to the page.  -        <inputtype= "button"ID= "Test1"value= "Test 1"onclick= "test1 ()">        <Buttontype= "button"ID= "Test2"><b>Test 2</b></Button>        <Scripttype= "Text/javascript">document.getElementById ("test2"). onclick=test2;//parentheses are not allowed here, and parentheses indicate the calling function.             /*Note: The function needs to be executed by a subsequent trigger, and the above sentence is not placed inside the function, and JavaScript is parsed from the top down to the code above,
If you have not resolved to the <body> Id--test2, you will get an error. So JavaScript code has to be put in the back. */ </Script> </Body></HTML>

JavaScript event concepts and monitoring events

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.