Javascript binding event

Source: Internet
Author: User

The simple binding time seems to be effective only when loading for the first time.
Document. getelementbyid ('yourhtmlelement'). onclick = Haha;
Function Haha (){
Alert ("Cleopatra ");
}
If the parameter is passed, it is a soy sauce.
Document. getelementbyid ("yourhtmlelement"). onclick = Haha ("your input ");
Function Haha (content ){
Alert (content );
}
This method will be executed once during the first loading and will not work.

For IE 6 (confirmed)
Document. getelementbyid ("yourhtmlelement"). attactevent /*(It should be attachevent, think8848 note) */("Onclick ",
New Function ("_ blackorwhite ('your input ');"));
Function _ blackorwhite (content ){
Alert (content );
}
Attactevent (Same as above, think8848 note) The method will not be executed when loading this statement. It is actually bound. It will only be executed during running.
For Mozilla

Document. getelementbyid ("yourhtmlelement"). addeventlistener ("onclick", _ blackorwhite, false );
Function _ blackorwhite (){
Alert ("Have you noticed any difference? ");
}

Note that parameter settings are not allowed for the key 1 event under Mozilla. If you pass parameters, the event will be executed during loading rather than when the response action occurs. Possible Solution: Mozilla can know who triggered this event, so that the parameter passed can be known by the event trigger through some means.

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.