ITPUB??ì3
ITPUB论坛 » WEB 2.0技术 » 小议Element三种事件绑定的优缺点


标题: 小议Element三种事件绑定的优缺点
离线 ShadowKiller
不会跳舞的猪


精华贴数 0
个人空间 0
技术积分 636 (2873)
社区积分 19 (7396)
注册日期 2004-9-17
论坛徽章:2
管理团队成员开发板块每日发贴之星    
      

发表于 2008-4-21 17:51 
小议Element三种事件绑定的优缺点

在网页中有三种事件绑定。
下面我来说说这三种事件,以及其优缺点(当然是别人写了,我照搬来说下的)
1. Traditional Binding  传统绑定
   所谓Traditional Binding 就是类似于 onclick= clickme() 这样的绑定

   其优缺点如下
   优点:
        a. 简单, 一致。 在所有浏览器里的表现都一样。 不用担心兼容性问题
        b. 事件处理函数中, this关键字指向当前的Element
    缺点:
        a. 只能工作在事件的bubbling阶段,不能在capturing阶段
        b. 只能绑定一个处理函数

2. DOM Binding:W3C
    基于W3C的事件绑定
   其优缺点如下:
   优点:
        a. 可工作在bubbling阶段,capturing阶段
            b. 事件处理函数中,this关键字指向当前的Element   
            c. 事件处理函数的第一个参数总是指向Event Object
            d. 可以绑定多个处理函数
   缺点:
        不能在IE下工作

3. DOM Binding: IE
    工作在IE中的Dom 绑定
   优点:
        可以绑定多个处理函数
   缺点:
        a. IE 只支持bubbling阶段的事件捕获
        b. 处理函数中的this关键字指向window对象而不是current Element
            c. event object 只能通过window.event获得
        d. 事件名必须写成ontype, 例如onclick onchange而不是click change  (个人觉得这个缺点有点牵强)
        e. 只能在IE中工作。 不能用于除IE以外的浏览器

好了。都列完了。 你可能对我说的不是很明白。 那么我只好使出杀手锏 ---- 列出原文

Traditional Binding
Advantages of Traditional Binding
The following are the advantages of using the traditional method:
• The biggest advantage of using the traditional method is that it’s incredibly simple and
consistent, in that you’re pretty much guaranteed that it’ll work the same no matter
what browser you use it in.
• When handling an event, the this keyword refers to the current element, which can be
very useful .
Disadvantages of Traditional Binding
The disadvantages of the traditional method are as follows:
• The traditional method only works with event bubbling, not capturing and bubbling.
• It’s only possible to bind one event handler to an element at a time. This has the potential
to cause confusing results when working with the popular window.onload property
(effectively overwriting other pieces of code that have used the same method of binding
events).
• The event object argument is only available in non-Internet Explorer browsers.


DOM Binding:W3C
Advantages of W3C Binding
The advantages to the W3C event-binding method are the following:
• This method supports both the capturing and bubbling phases of event handling. The
event phase is toggled by setting the last parameter of addEventListener to false (for
bubbling) or true (for capturing).
• Inside of the event handler function, the this keyword refers to the current element.
• The event object is always available in the first argument of the handling function.
• You can bind as many events to an element as you wish, with none overwriting previously
bound handlers.
Disadvantage of W3C Binding
The disadvantage to the W3C event-binding method is the following:
• It does not work in Internet Explorer; you must use IE’s attachEvent function instead.

IE Binding
Advantage of IE Binding
The advantage to Internet Explorer’s event-binding method is the following:
• You can bind as many events to an element as you desire, with none overwriting previously
bound handlers.
Disadvantages of IE Binding
The disadvantages to Internet Explorer’s event-binding method are the following:
• Internet Explorer only supports the bubbling phase of event capturing.
• The this keyword inside of event listener functions points to the window object, not the
current element (a huge drawback of IE).
• The event object is only available in the window.event parameter.
• The name of the event must be named as ontype—for example, onclick instead of just
requiring click.
• It only works in Internet Explorer. You must use the W3C’s addEventListener for
non-IE browsers.


__________________
When you wanna get the most , there's no easy way out; when you ready to go and your heart left in doubt, Don't give up your faith , cause you can win, in this thing called love.Love can conquer all.
只看该作者    顶部
离线 iooyoo
迷眼流金


精华贴数 0
个人空间 20
技术积分 4018 (321)
社区积分 3386 (369)
注册日期 2006-6-15
论坛徽章:20
现任管理团队成员2008年新春纪念徽章    
      

发表于 2008-4-22 19:19 


QUOTE:
原帖由 ShadowKiller 于 2008-4-21 17:51 发表
好了。都列完了。 你可能对我说的不是很明白。 那么我只好使出杀手锏 ---- 列出原文

举例更好  


__________________

使君欲醉离亭酒
酒醒离愁转有
紫禁多时虚右
苕霄留难久
一声歌掩双罗袖
日落乱山春后
犹有东城烟柳
青荫长依旧
只看该作者    顶部
离线 ShadowKiller
不会跳舞的猪


精华贴数 0
个人空间 0
技术积分 636 (2873)
社区积分 19 (7396)
注册日期 2004-9-17
论坛徽章:2
管理团队成员开发板块每日发贴之星    
      

发表于 2008-4-23 10:52 
那就等我整理一个比较详细的例子。  嘿嘿  可能会很漫长 哦


__________________
When you wanna get the most , there's no easy way out; when you ready to go and your heart left in doubt, Don't give up your faith , cause you can win, in this thing called love.Love can conquer all.
只看该作者    顶部
离线 iooyoo
迷眼流金


精华贴数 0
个人空间 20
技术积分 4018 (321)
社区积分 3386 (369)
注册日期 2006-6-15
论坛徽章:20
现任管理团队成员2008年新春纪念徽章    
      

发表于 2008-4-24 10:18 
呵呵,坑越大越难填啊,理解



__________________

使君欲醉离亭酒
酒醒离愁转有
紫禁多时虚右
苕霄留难久
一声歌掩双罗袖
日落乱山春后
犹有东城烟柳
青荫长依旧
只看该作者    顶部
在线/呼叫 justforregister
SAP


精华贴数 1
个人空间 10
技术积分 35163 (21)
社区积分 8025 (176)
注册日期 2005-6-10
论坛徽章:241
现任管理团队成员ITPUB元老NBA2008季后赛纪念徽章欧洲冠军杯纪念徽章NBA常规赛纪念章管理团队2007贡献徽章
参与2007年甲骨文全球大会(中国上海)纪念ITPUB北京香山2007年会纪念徽章会员2007贡献徽章2008北京奥运纪念徽章:网球2008北京奥运纪念徽章:马术体育版块博采纪念徽章

发表于 2008-4-30 00:43 
nice job


__________________
只看该作者    顶部
离线 iooyoo
迷眼流金


精华贴数 0
个人空间 20
技术积分 4018 (321)
社区积分 3386 (369)
注册日期 2006-6-15
论坛徽章:20
现任管理团队成员2008年新春纪念徽章    
      

发表于 2008-5-20 16:39 
坑啊


__________________

使君欲醉离亭酒
酒醒离愁转有
紫禁多时虚右
苕霄留难久
一声歌掩双罗袖
日落乱山春后
犹有东城烟柳
青荫长依旧
只看该作者    顶部
离线 bluecheustb



精华贴数 0
个人空间 0
技术积分 2 (221664)
社区积分 0 (1809678)
注册日期 2008-7-14
论坛徽章:0
      
      

发表于 2008-7-14 13:52 
版主,不好意思,我下载的你的很久以前上传的javascript学习的书,,为什么下载下来打开以后右侧却显示“无法显示”呢?刚出道混,望楼主帮忙哦~~~


只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问