当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 让IE8支持DOM 2(不用框架!)

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 让IE8支持DOM 2(不用框架!)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 393 ::
收藏到网摘: n/a

众所周知,IE8开放了对DOM原型的支持以及ECMA v5的两个新方法——Object.defineProperty和Object.getOwnPropertyDexcriptor(单词好长……),并且这两个新方法居然只能用于DOM。 微软此举的意图很明显——以一种极小的代价“实现” DOM2的全部接口。这里举两个例子:
复制代码 代码如下:

Element.prototype.addEventListener = function(evtType, evtHandler) {
return this.attachEvent('on' + evtType, evtHandler);
}
Object.defineProperty(Event.prototype, 'target', {
get: function() { return this.srcElement },
set: function(v) { return this.srcElement = v }
});

这似乎和早年使用__definegetter__之流让Firefox兼容IE的方法一致,不过这次使用的是完全标准(DOM原型和ECMA v5)的方法来弥补IE的缺憾。可能IE8开发时重写了渲染引擎但是没来及(我很乐观……)发布新的DOM接口(可能是为了兼容第三方应用程序),所以给出了这个方案。