<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></title> 
<link>http://www.bizeway.net/index.php</link> 
<description><![CDATA[网务通 - 网务公司发展之路]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></copyright>
<item>
<link>http://www.bizeway.net/read.php?</link>
<title><![CDATA[Javascript的IE和Firefox兼容性汇编 ]]></title> 
<author>ArthurXF &lt;arthurxf@gmail.com&gt;</author>
<category><![CDATA[Javascript]]></category>
<pubDate>Thu, 04 Jun 2009 06:22:19 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?</guid> 
<description>
<![CDATA[ 
	1. document.form.item 问题<br/> &nbsp; &nbsp;(1)现有问题：<br/> &nbsp; &nbsp; &nbsp; &nbsp;现有代码中存在许多 document.formName.item("itemName") 这样的语句，不能在 MF 下运行<br/> &nbsp; &nbsp;(2)解决方法：<br/> &nbsp; &nbsp; &nbsp; &nbsp;改用 document.formName.elements["elementName"]<br/> &nbsp; &nbsp;(3)其它<br/> &nbsp; &nbsp; &nbsp; &nbsp;参见 2<br/><br/>2. 集合类对象问题<br/> &nbsp; &nbsp;(1)现有问题：<br/> &nbsp; &nbsp; &nbsp; &nbsp;现有代码中许多集合类对象取用时使用 ()，IE 能接受，MF 不能。<br/> &nbsp; &nbsp;(2)解决方法：<br/> &nbsp; &nbsp; &nbsp; &nbsp;改用 [] 作为下标运算。如：document.forms("formName") 改为 document.forms["formName"]。<br/> &nbsp; &nbsp; &nbsp; &nbsp;又如：document.getElementsByName("inputName")(1) 改为 document.getElementsByName("inputName")[1]<br/> &nbsp; &nbsp;(3)其它<br/><br/>3. window.event<br/> &nbsp; &nbsp;(1)现有问题：<br/> &nbsp; &nbsp; &nbsp; &nbsp;使用 window.event 无法在 MF 上运行<br/> &nbsp; &nbsp;(2)解决方法：<br/> &nbsp; &nbsp; &nbsp; &nbsp;MF 的 event 只能在事件发生的现场使用，此问题暂无法解决。可以这样变通：<br/> &nbsp; &nbsp; &nbsp; &nbsp;原代码(可在IE中运行)：<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input type="button" name="someButton" value="提交" onclick="javascript:gotoSubmit()"/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<script language="javascript"><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;function gotoSubmit() {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(window.event); &nbsp; &nbsp;// use window.event<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</script><br/><br/><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;新代码(可在IE和MF中运行)：<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input type="button" name="someButton" value="提交" onclick="javascript:gotoSubmit(event)"/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<script language="javascript"><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;function gotoSubmit(evt) {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;evt = evt ? evt : (window.event ? window.event : null);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(evt); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // use evt<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</script><br/> &nbsp; &nbsp; &nbsp; &nbsp;此外，如果新代码中第一行不改，与老代码一样的话(即 gotoSubmit 调用没有给参数)，则仍然只能在IE中运行，但不会出错。所以，这种方案 tpl 部分仍与老代码兼容。<br/><br/><br/><br/>--------------------------------------------------------------------------------<br/>对原文的补充：事件的对象，在IE中是window.event.srcElement，在Firefox中是event.target，而在Opera中则两者都支持。还是用例子来说明。 <br/>event.srcElement/event.target<br/>//***********************************<br/><HTML><br/><HEAD><br/><TITLE> event的跨浏览器测试 </TITLE><br/><SCRIPT LANGUAGE="JavaScript"><br/><!--<br/>//Firefox中在写关于event的函数的时候，必须把event对象作为参数传递给函数，这样才能使用event对象<br/>function doTestEvent( evt )<br/>{<br/> &nbsp;//如果是IE/Opera，我们就用 srcElement 来获取触发事件的对象<br/> &nbsp;//如果是Firefox，我们就用 target 来获取触发事件的对象<br/> &nbsp;var src = evt.srcElement ? evt.srcElement : evt.target;<br/> &nbsp;alert( src.value );<br/>}<br/>//--><br/></script><br/></head><br/><body><br/><br/><form name="frmtest"><br/><input type="button" value="event 测试" onclick="doTestEvent(event);" name="bttest"><br/></form><br/><br/></body><br/></html> <br/>//*********************************** <br/><br/>--------------------------------------------------------------------------------<br/><br/><br/><br/><br/><br/>4. HTML 对象的 id 作为对象名的问题<br/> &nbsp; &nbsp;(1)现有问题<br/> &nbsp; &nbsp; &nbsp; &nbsp;在 IE 中，HTML 对象的 ID 可以作为 document 的下属对象变量名直接使用。在 MF 中不能。<br/> &nbsp; &nbsp;(2)解决方法<br/> &nbsp; &nbsp; &nbsp; &nbsp;用 getElementById("idName") 代替 idName 作为对象变量使用。<br/><br/><br/><br/>5. 用idName字符串取得对象的问题<br/> &nbsp; &nbsp;(1)现有问题<br/> &nbsp; &nbsp; &nbsp; &nbsp;在IE中，利用 eval(idName) 可以取得 id 为 idName 的 HTML 对象，在MF 中不能。<br/> &nbsp; &nbsp;(2)解决方法<br/> &nbsp; &nbsp; &nbsp; &nbsp;用 getElementById(idName) 代替 eval(idName)。<br/><br/>6. 变量名与某 HTML 对象 id 相同的问题<br/> &nbsp; &nbsp;(1)现有问题<br/> &nbsp; &nbsp; &nbsp; &nbsp;在 MF 中，因为对象 id 不作为 HTML 对象的名称，所以可以使用与 HTML 对象 id 相同的变量名，IE 中不能。<br/> &nbsp; &nbsp;(2)解决方法<br/> &nbsp; &nbsp; &nbsp; &nbsp;在声明变量时，一律加上 var ，以避免歧义，这样在 IE 中亦可正常运行。<br/> &nbsp; &nbsp; &nbsp; &nbsp;此外，最好不要取与 HTML 对象 id 相同的变量名，以减少错误。<br/> &nbsp; &nbsp;(3)其它<br/> &nbsp; &nbsp; &nbsp; &nbsp;参见 问题4<br/><br/>7. event.x 与 event.y 问题<br/> &nbsp; &nbsp;(1)现有问题<br/> &nbsp; &nbsp; &nbsp; &nbsp;在IE 中，event 对象有 x, y 属性，MF中没有。<br/> &nbsp; &nbsp;(2)解决方法<br/> &nbsp; &nbsp; &nbsp; &nbsp;在MF中，与event.x 等效的是 event.pageX。但event.pageX IE中没有。<br/> &nbsp; &nbsp; &nbsp; &nbsp;故采用 event.clientX 代替 event.x。在IE 中也有这个变量。<br/> &nbsp; &nbsp; &nbsp; &nbsp;event.clientX 与 event.pageX 有微妙的差别（当整个页面有滚动条的时候），不过大多数时候是等效的。<br/><br/><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;如果要完全一样，可以稍麻烦些：<br/> &nbsp; &nbsp; &nbsp; &nbsp;mX = event.x ? event.x : event.pageX;<br/> &nbsp; &nbsp; &nbsp; &nbsp;然后用 mX 代替 event.x<br/> &nbsp; &nbsp;(3)其它<br/> &nbsp; &nbsp; &nbsp; &nbsp;event.layerX 在 IE 与 MF 中都有，具体意义有无差别尚未试验。<br/><br/><br/><br/>8. 关于frame<br/> &nbsp; (1)现有问题<br/> &nbsp; &nbsp; &nbsp; &nbsp; 在 IE中 可以用window.testFrame取得该frame，mf中不行<br/> &nbsp; (2)解决方法<br/> &nbsp; &nbsp; &nbsp; &nbsp; 在frame的使用方面mf和ie的最主要的区别是：<br/>如果在frame标签中书写了以下属性：<br/><frame src="/xx.htm" id="frameId" name="frameName" /><br/>那么ie可以通过id或者name访问这个frame对应的window对象<br/>而mf只可以通过name来访问这个frame对应的window对象<br/>例如如果上述frame标签写在最上层的window里面的htm里面，那么可以这样访问<br/>ie： window.top.frameId或者window.top.frameName来访问这个window对象<br/>mf： 只能这样window.top.frameName来访问这个window对象<br/><br/>另外，在mf和ie中都可以使用window.top.document.getElementById("frameId")来访问frame标签<br/>并且可以通过window.top.document.getElementById("testFrame").src = 'xx.htm'来切换frame的内容<br/>也都可以通过window.top.frameName.location = 'xx.htm'来切换frame的内容<br/>关于frame和window的描述可以参见bbs的‘window与frame’文章<br/>以及/test/js/test_frame/目录下面的测试<br/>----adun 2004.12.09修改<br/><br/>9. 在mf中，自己定义的属性必须getAttribute()取得<br/>10.在mf中没有 &nbsp;parentElement parement.children &nbsp;而用<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parentNode parentNode.childNodes<br/> &nbsp; childNodes的下标的含义在IE和MF中不同，MF使用DOM规范，childNodes中会插入空白文本节点。<br/> &nbsp;一般可以通过node.getElementsByTagName()来回避这个问题。<br/> &nbsp; 当html中节点缺失时，IE和MF对parentNode的解释不同，例如<br/> &nbsp; <form><br/> &nbsp; <table><br/> &nbsp; &nbsp; &nbsp; &nbsp;<input/><br/> &nbsp; </table><br/> &nbsp; </form><br/> &nbsp; MF中input.parentNode的值为form, 而IE中input.parentNode的值为空节点<br/><br/><br/><br/> &nbsp;MF中节点没有removeNode方法，必须使用如下方法 node.parentNode.removeChild(node)<br/><br/>11.const 问题<br/> &nbsp;(1)现有问题:<br/> &nbsp; &nbsp; 在 IE 中不能使用 const 关键字。如 const constVar = 32; 在IE中这是语法错误。<br/> &nbsp;(2)解决方法:<br/> &nbsp; &nbsp; 不使用 const ，以 var 代替。<br/><br/>12. body 对象<br/> &nbsp; MF的body在body标签没有被浏览器完全读入之前就存在，而IE则必须在body完全被读入之后才存在<br/><br/>13. url encoding<br/>在js中如果书写url就直接写&不要写&amp;例如var url = 'xx.jsp?objectName=xx&amp;objectEvent=xxx';<br/>frm.action = url那么很有可能url不会被正常显示以至于参数没有正确的传到服务器<br/>一般会服务器报错参数没有找到<br/>当然如果是在tpl中例外，因为tpl中符合xml规范，要求&书写为&amp;<br/>一般MF无法识别js中的&amp;<br/><br/><br/>14. nodeName 和 tagName 问题<br/> &nbsp;(1)现有问题：<br/> &nbsp; &nbsp; 在MF中，所有节点均有 nodeName 值，但 textNode 没有 tagName 值。在 IE 中，nodeName 的使用好象<br/> &nbsp; &nbsp; 有问题（具体情况没有测试，但我的IE已经死了好几次）。<br/> &nbsp;(2)解决方法：<br/> &nbsp; &nbsp; 使用 tagName，但应检测其是否为空。<br/><br/>15. 元素属性<br/> &nbsp; IE下 input.type属性为只读，但是MF下可以修改<br/><br/><br/>16. document.getElementsByName() 和 document.all[name] 的问题<br/> &nbsp;(1)现有问题：<br/> &nbsp; &nbsp; 在 IE 中，getElementsByName()、document.all[name] 均不能用来取得 div 元素（是否还有其它不能取的元素还不知道）。<br/><br/>Tags - <a href="tag.php?tag=javascript" rel="tag">javascript</a> , <a href="tag.php?tag=ie" rel="tag">ie</a> , <a href="tag.php?tag=firefox" rel="tag">firefox</a>
]]>
</description>
</item><item>
<link>http://www.bizeway.net/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] Javascript的IE和Firefox兼容性汇编 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>