当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS用 或 || 来兼容FireFox!

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 中的 JS用 或 || 来兼容FireFox!


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 193 ::
收藏到网摘: n/a

点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]

找到 document.body.onclick = function(evt),
在IE下,这个evt是不会有的,但是在fireFox下(opera下好像也是)会默认传这个参数.在IE下,这个参数是 null ,想兼容,就这样写.
继续向下,
evt = evt || window.event;
在IE下,evt 就会指向:window.event,在fireFox下,就会指向那个默认参数.
因为在IE下 evt || window.event 相当于: null || window.event,结果还是window.event
而在fireFox下,就相当于 evt || null ,结果就是evt
相下看:
o.previousSibling.href || o.previousSibling.previousSibling.href
前面一个表达式用于IE下,后面一个用于FireFox下.
因为在IE下,XMLDom没有preserveWhiteSpace这个属性,即:把空白也当作一个节点,而IE则默认为false,即把空白不看成一个节点.
这里说到了XMLDom,似乎和上面所说的不相关,但是在FireFox下 previousSibling就是空白,除非两个HTML标签之间没有任何形式的空格.
<a href="http://www.blueidea.com/articleimg/bbsimg/smile.gif"/></a>
<a href="图片地址">打开</a>
两个<a>之间有换行(属于空格的一种),所以在FireFox下,取下面一个<a>的前一个节点的话,就必须用:
o.previousSibling.previousSibling.href
可能你还是没有看明白,没关系,在举个简单的:
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]