侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130559 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

js绑定事件的常用方式

2023-09-06 星期三 / 0 评论 / 0 点赞 / 33 阅读 / 1301 字

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN

<?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事件绑定</title><script type="text/javascript">/** * 绑定事件的方式:用事件属性绑定事件函数 * 优点:1:完成行为的分离  * 2:便于操作当事对象,因为function是作为on***的属性出现的,可直接用this引用当事对象。 * 3:方便读取事件对象,事件触发时系统自动把事件对象传递给事件函数,已其一个来传 */	   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>

广告 广告

评论区