JavaScript Learning Notes

Source: Internet
Author: User

1, the = = = operator compares the value of two objects to the type of!==.

Cases:

var i = 0;var j = ' 0 '; I ==j//Truei = = = J//False

2. Events

<DivID= ' Test '>    <ButtonID= "BTN"/>
<a href= "www.baidu.com" id= "BD" > Baidu </a></Div><Script>document.getElementById ('btn'). AddEventListener ('Click', Demo1); document.getElementById ('b'). AddEventListener ('Click', Demo2);
    document.getElementById (' BD '). AddEventListener (' click ', Demo3);
 function   Demo1 (e) {alert ( "  test1   " ); 
//e.stoppropagation ();//block event bubbling} function Demo2 () {alert ( " test2 " );}
function Demo3 (e) {     alert (' test3 ');
   E.preventdefault ();//block default behavior}
</ Script >

When the button is clicked, event bubbling occurs, so the event is executed from the bottom up, that is, Button-->div.

The result is: Eject test1 first, then eject Test2.

Block event bubbling: Using E.stoppropagation ();

3. How to create objects

<!-- Creating Objects  -     /* Method One *    /people = new Object ();    People.age =;    People.name = ' Baohua ';    document.write (' Name: ' +people.name+ ' Age: ' +people.age ');    /* Method Two */    animal = {Age        : $  ,        type: ' Dog ',        voice:function () {        alert (' Brak ');    }    };    Document.writeln (' Animal type: ' +animal.type+ ' animal Age: ' +animal.age ');    Animal.voice ();    /* Method Three    *  /function Plant (type,name) {        this.type = type;        this.name = name;    }    Flower = new Plant (' flower ', ' rose ');    Document.writeln ("Plant type:" +flower.type+ "Plant Name:" +flower.name ");

JavaScript Learning Notes

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.