A brief analysis of common methods of js binding events
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>JS event binding</title><script type="text/javascript">/** * Method of binding events: bind event functions with event attributes* Advantages: 1: Complete the separation of behaviors* 2: Easy to operate the party object, because function appears as an on*** attribute, you can directly refer to the party object with this. * 3: It is convenient to read event objects. When the event is triggered, the system automatically passes the event object to the event function. One of them is passed*/ window.onload=function(){ var k=document.getElementById('k').onclick=function(event){ var jj=document.getElementById('jj'); jj.style.top=event.clientX+'px'; jj.style.left=event.clientY+'px'; } } </script><style>#k{width:60px;height:80px; background-color:#80ffff;}#jj{width:60px ;height:80px;background-color:#ffff00;z-index:1000;position:absolute;}</style></head><body><div id="k"></div><div id="jj"></div></body></html>The above article briefly analyzes the common methods of js binding events are all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.