JavaScript makes Web pages friendly to users, and there are three ways to bind when using JS for time binding.
The first: beginners and general wording
1 <DivID= "Dom0">2 <inputtype= "button"value= "Click0"onclick= "dom0 ();" />3 </Div>4 <Script>5 functiondom0 () {6 Alert ('Dom0 Leval');7 }8 </Script>
The second type: programmers often use the notation
1 <DivID= "Dom1">2 <inputtype= "button"value= "Click1" />3 </Div>4 <Script>5 vardom1=document.getElementById ('dom1'). Firstelementchild;6 Dom1.onclick=function(){7 Alert ('Dom1 Leval');8 }9 </Script>
The third type: uncommon but will encounter in the interview
1 <DivID= "Dom2">2 <inputtype= "button"value= "Click2" />3 </Div>4 <Script>5 varDom2=document.getElementById ('Dom2'). Firstelementchild;6 Dom2.addeventlistener ('Click',function () {7 Alert ('Dom2 Leval');8 },false);9 </Script>
In the third notation,AddEventListener(event, function, False | | True), false represents the bubbling model, and true represents the capture model. The default is False.
Originality is not easy, respect copyright. Reprint Please specify source:http://www.cnblogs.com/xsmile/
Three ways to bind events in JavaScript