好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

window、document、html、body、element的事件属性比较_html/css_

在分析jQuery的事件的时候有提到绑定事件的方式:

Dean Edwards的跨浏览器事件绑定使用的方式是

element["on" + type] = handleEvent; 

  即绑定的事件的前提条件是element.onxxx属性必须存在。

jQuery的绑定方式是使用浏览器的绑定绑定方法

if ( elem.addEventListener ) {  elem.addEventListener( type, eventHandle, false );} else if ( elem.attachEvent ) {  elem.attachEvent( "on" + type, eventHandle );} 

  为什么不用Dean Edwards使用的方式来绑定?

原因:

  并非所有浏览器支持的事件都有对应的["on" + type]属性。比较典型的例子动画事件


#myDIV {
margin:25px;
width:550px;
height:100px;
background:orange;
position:relative;
font-size:20px;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes mymove {
from {top: 0px;}
to {top: 200px;}
}
@keyframes mymove {
from {top: 0px;}
to {top: 200px;}
}


该实例使用了 addEventListener() 方法为 DIV 元素添加"animationstart", "animationiteration" 和 "animationend" 事件。

点我开始动画

查看更多关于window、document、html、body、element的事件属性比较_html/css_的详细内容...

  阅读:38次