js events registration

1. Elemental .onclick = function // click event

var Box = document.getElementById ( ' Box ' ) 
box.onclick = function () { 
  the console.log ( ' Box is clicked ' ) 
}

 2. Give a label registration click event 

<a id= "box" href= "# "> Click </a> 
<IMG ID = " IMG " the src = " ./img01.jpg " Alt = "" > var Box = document.getElementById ( ' Box ' )
 var IMG = document.getElementById ( ' IMG ' ) 
box.onclick = function () { 
  img.src = ' ./img01.jpg ' // return to false;      // prevents the default behavior of a tag 
}


  

 

Guess you like

Origin www.cnblogs.com/zhaodz/p/11617549.html