您当前的位置: 首页 > 学无止境 > JS经典实例 网站首页JS经典实例
javascript事件篇-事件的动态绑定
发布时间:2016-12-31 15:30:57编辑:雪饮阅读()
事件添加的使用:window对象或dom对象皆可用
<style>
#box{
width:100px;
height:100px;
background:pink;
}
</style>
<div id="box"></div>
<script type="text/javascript">
function cs(){
var that=window.event.srcElement;//当前事件作用对象
console.log(that);
alert(that);
}
var box=document.getElementById("box");
box.addEventListener("click",cs,false);
</script>
关键字词:javascript,事件