Event Binding Method 1: Binding in Properties
<input type="button" value="+" onclick="fun1()"> <script> function fun1(){ alert(123); } </script>
The event binding method has a parameter this, this refers to this tag
<div class="div1" onclick="fun1(this)">div1</div> <script> function fun1(e){ alert(e.innerHTML); } </script>
Event binding method 2: Binding in the script tag
<div class="div1">div1</div> <script> var tmp=document.getElementsByClassName("div1")[0]; tmp.onclick = function (){ // onclick is not followed by parentheses alert( 123 ); } </script>
Event binding method two this
<div class="div1">div1</div> <script> var tmp=document.getElementsByClassName("div1")[0]; tmp.onclick=function(){ alert( this .innerHTML); // this also refers to the tag } </ script >