首页
论坛
门户
空间
手机版
IXPUB
插件
收藏
设置
注册
登录
商店
搜索
培训
Wiki
Blog
归档
丛书
退出
ITPUB论坛
»
WEB 2.0技术
» 小议Element三种事件绑定的优缺点
‹‹ 上一主题
|
下一主题 ››
投票
交易
悬赏
活动
评价
|
打印
|
推荐
|
订阅
|
收藏
标题: 小议Element三种事件绑定的优缺点
ShadowKiller
不会跳舞的猪
精华贴数 0
个人空间
0
技术积分 636 (2873)
社区积分 19 (7396)
注册日期 2004-9-17
论坛徽章:2
#1
使用道具
发表于 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
#2
使用道具
发表于 2008-4-22 19:19
QUOTE:
原帖由
ShadowKiller
于 2008-4-21 17:51 发表
好了。都列完了。 你可能对我说的不是很明白。 那么我只好使出杀手锏 ---- 列出原文
举例更好
__________________
使君欲醉离亭酒
酒醒离愁转有
紫禁多时虚右
苕霄留难久
一声歌掩双罗袖
日落乱山春后
犹有东城烟柳
青荫长依旧
只看该作者
ShadowKiller
不会跳舞的猪
精华贴数 0
个人空间
0
技术积分 636 (2873)
社区积分 19 (7396)
注册日期 2004-9-17
论坛徽章:2
#3
使用道具
发表于 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
#4
使用道具
发表于 2008-4-24 10:18
呵呵,坑越大越难填啊,理解
__________________
使君欲醉离亭酒
酒醒离愁转有
紫禁多时虚右
苕霄留难久
一声歌掩双罗袖
日落乱山春后
犹有东城烟柳
青荫长依旧
只看该作者
justforregister
SAP
精华贴数 1
个人空间
10
技术积分 35163 (21)
社区积分 8025 (176)
注册日期 2005-6-10
论坛徽章:241
#5
使用道具
发表于 2008-4-30 00:43
nice job
__________________
Go to Hell
只看该作者
iooyoo
迷眼流金
精华贴数 0
个人空间
20
技术积分 4018 (321)
社区积分 3386 (369)
注册日期 2006-6-15
论坛徽章:20
#6
使用道具
发表于 2008-5-20 16:39
坑啊
__________________
使君欲醉离亭酒
酒醒离愁转有
紫禁多时虚右
苕霄留难久
一声歌掩双罗袖
日落乱山春后
犹有东城烟柳
青荫长依旧
只看该作者
bluecheustb
精华贴数 0
个人空间
0
技术积分 2 (221664)
社区积分 0 (1809678)
注册日期 2008-7-14
论坛徽章:0
#7
使用道具
发表于 2008-7-14 13:52
版主,不好意思,我下载的你的很久以前上传的javascript学习的书,,为什么下载下来打开以后右侧却显示“无法显示”呢?刚出道混,望楼主帮忙哦~~~
只看该作者
投票
交易
悬赏
活动
相关内容
ITPUB论坛
≡ 数据库技术 ≡
> Oracle数据库管理
> Oracle开发
> Oracle Developer Suite
> Oracle入门与认证
> Oracle专题深入讨论
> Oracle新技术/11g
> Oracle电子文档
> Oracle Application Server套件
> IBM数据库产品
> MS SQL Server
> Sybase管理与开发
> MySQL及其它开源数据库
> 内存数据库
> 数据仓库与数据挖掘
> 移动及嵌入式数据库
≡ 企业信息化 ≡
> ERP产品与实践
> CRM产品与实践
> HR产品与实践
> 物流
> 供应链
> 供应链建模与仿真
> 物流设备与系统工程
> 企业管理咨询
> 管理协同与办公自动化
> IT服务管理
> 数据中心建设
> ERP二次开发
> Oracle ERP
> EBS相关文档
> PeopleSoft与JDE
> SAP R/3
> SAP Business One开发与快速实施
> SAP财务及CRM
> SAP后勤及HR
> mySAP ERP
> 系统开发及跨应用设置
> SAP相关文档
> 国外其它ERP产品
> 国内ERP产品
≡ 开发技术 ≡
> Java入门与认证版
> Java web开发及框架技术
> Java企业开发
> ASP.NET
> .Net企业开发与应用
> WEB程序开发
> WEB 2.0技术
> 动态语言
> 移动与游戏开发
≡ 系统设计与项目管理 ≡
> 系统分析与UML
> 系统分析与UML精华区
> 项目管理
> 项目过程
> 软件测试
> 算法讨论与研究
≡ IBM软件技术园地 ≡
> IBM数据库产品
> Lotus
> Tivoli
> Websphere
> Rational
> 与SOA相关的IBM产品与技术
> IBM软件技术精英协会
> 软件技术精英活动专版
≡ 操作系统与硬件 ≡
> AIX及IBM产品【已迁移到IXPUB】
> HP-UX及HP产品【已迁移到IXPUB】
> Solaris及SUN产品【已迁移到IXPUB】
> Linux及其应用 【已迁移到IXPUB】
> 其它UNIX系统【已迁移到IXPUB】
> windows系统及微软相关产品 【已迁移到IXPUB】
> 存储设备与容灾技术 【已迁移到IXPUB】
> 服务器 【已迁移到IXPUB】
≡ 行业纵向讨论区 ≡
> IT业界评论与展望
> 政府与教育事业
> 中国政府信息主管联盟
> 电信行业
> 金融行业
> 医卫行业
> 制造行业
> 电力行业
> 信息安全与审计
≡ 会员交流 ≡
> IT职业生涯
> 招聘求职商务信息
> 投资理财
> 体育世界
> 体育博彩专版
> 旅游,驴友
> 汽车世界
> 外语角
> 数码摄影
> 你的故事我的歌
> 音乐推荐区
> 电子图书与IT文档资料
> 软件交流
> 软件交流精华区
≡ ITPUB产品与服务 ≡
> ITPUB地面活动专版
> BLOG天地
> WIKI世界
> 授权用户区
> 站务管理
技术积分榜
社区积分榜
徽章
电子杂志
会员
团队
统计
邮箱
游乐场
帮助
TOP
CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号
联系我们
法律顾问
控制面板首页
编辑个人资料
积分交易
公众用户组
好友列表
升级个人空间
基本概况
论坛排行
主题排行
发帖排行
积分排行
在线时间
管理团队
管理统计