<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="css/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>子寒博客—关注互联网，WEB前端技术和WEB设计 - 前端开发</title><link>http://zihan.cn/</link><description>记录工作，感悟生活，品味人生。 - </description><generator>RainbowSoft Studio Z-Blog 1.8 Arwen Build 90619</generator><language>zh-CN</language><copyright>Copyright 2005-2010 ZiHan.cn. Some Rights Reserved.</copyright><pubDate>Wed, 08 Sep 2010 04:52:16 +0800</pubDate><item><title>php.ini register_globals must is Off!错误</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/58.htm</link><pubDate>Fri, 02 Jul 2010 16:33:43 +0800</pubDate><guid>http://zihan.cn/post/58.htm</guid><description><![CDATA[<p>新服务器在安装php程序的时候出现了php.ini register_globals must is Off!这个错误。在网上查找后解决了。</p><p>解决方法：将系统c盘windows目录下和php配置文件里的php.ini文件里register_globals=on改成register_globals改成off，重新启动IIS（我的服务器是win2003系统，PHP是用IIS来部署的。），问题解决。</p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/58.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=58</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=58&amp;key=49ba306d</trackback:ping></item><item><title>wordpress搬迁注意的两个问题</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/57.htm</link><pubDate>Thu, 01 Jul 2010 16:18:54 +0800</pubDate><guid>http://zihan.cn/post/57.htm</guid><description><![CDATA[<p>本周升级云服务器，系统资源大大增强。在帮<a target="_blank" href="http://bai80.com">修远兮</a>搬迁wordpress的时候，出现了两个问题。两个服务器都是采用windows2003系统，数据库和程序文件一并搬迁。</p><p>1.服务器用phpmyadmin管理，在导入数据库的时候，其他站点的数据库都能列出表。唯有WP的列不出来。</p><p>原因：未知。</p><p>解决办法：新建一个数据库，将原来备份的sql文件导入新数据库即可。</p><p>2.导入数据库后，部分php文件出现如下错误：Warning: Cannot modify header information - headers already sent by (output started at /bai80.com/wp-config.php:1) in /bai80.com/wp-includes/pluggable.php on line 569</p><p>原因：编码BUG。<br /><br />解决办法：找到<span style="color: rgb(255, 0, 0);">wp-config.php</span>文件，将文件下载到本地，用记事本打开，直接点击另存为，然后在编码选项那里选择<span style="color: rgb(255, 0, 0);">ANSI</span>，保存后再上传到空间覆盖之前的文件，刷新后，问题解决。</p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/57.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=57</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=57&amp;key=021c765f</trackback:ping></item><item><title>JS函数集合大全</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/48.htm</link><pubDate>Thu, 25 Feb 2010 18:21:28 +0800</pubDate><guid>http://zihan.cn/post/48.htm</guid><description><![CDATA[<p><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;"><span class="Apple-style-span" style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;"><p style="margin: 1em 0px 0.5em; padding: 0px;"><font size="2">1.document.write(&quot;&quot;); 输出语句<br />2.JS中的注释为//<br />3.传统的HTML文档顺序是:document-&gt;html-&gt;(head,body)<br />4.一个浏览器窗口中的DOM顺序是:window-&gt;(navigator,screen,history,location,document)<br />5.得到表单中元素的名称和值:<font style="background-color: rgb(255, 255, 153);">document.getElementById</font><font style="background-color: rgb(255, 255, 153);">(&quot;表单中元素的ID号&quot;).name(或value)</font><br />6.一个小写转大写的JS: document.getElementById(&quot;output&quot;).value = document.getElementById(&quot;input&quot;).value.toUpperCase();<br />7.JS中的值类型:String,Number,Boolean,Null,Object,Function<br />8.JS中的字符型转换成数值型:parseInt(),parseFloat()<br />9.JS中的数字转换成字符型:(&quot;&quot;+变量)<br />10.JS中的取字符串长度是:(<font style="background-color: rgb(255, 255, 153);">length</font>)<br />11.JS中的字符与字符相连接使用+号.<br />12.JS中的比较操作符有:==等于,!=不等于,&gt;,&gt;=,&lt;.&lt;=<br />13.JS中声明变量使用:var来进行声明<br />14.JS中的判断语句结构:if(condition){}else{}<br />15.JS中的循环结构:for([initial expression];[condition];[upadte expression]) {inside loop}<br />16.循环中止的命令是:break<br />17.JS中的函数定义:function functionName([parameter],...){statement[s]}<br />18.<font style="background-color: rgb(255, 255, 153);">当文件中出现多个form表单时.可以用document.forms[0],document.forms[1]来代替.</font><br />19.窗口:打开窗口window.open(), 关闭一个窗口:window.close(), 窗口本身:self<br />20.状态栏的设置:<font style="background-color: rgb(255, 255, 153);">window.status=&quot;字符&quot;;</font><br />21.弹出提示信息:window.alert(&quot;字符&quot;);<br />22.弹出确认框:window.confirm();<br />23.弹出输入提示框:window.prompt();<br />24.指定当前显示链接的位置:window.location.href=&quot;URL&quot;<br />25.取出窗体中的所有表单的数量:<font style="background-color: rgb(255, 255, 153);">document.forms.length</font><br />26.关闭文档的输出流:<font style="background-color: rgb(255, 255, 153);">document.close();</font><br />27.字符串追加连接符:+=<br />28.创建一个文档元素:document.createElement(),document.createTextNode()<br />29.得到元素的方法:document.getElementById()<br />30.设置表单中所有文本型的成员的值为空:<br />var form = window.document.forms[0]<br />for (var i = 0; i&lt;form.elements.length;i++){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (form.elements[i].type == &quot;text&quot;){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; form.elements[i].value = &quot;&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />}<br />31.复选按钮在JS中判断是否选中:document.forms[0].checkThis.checked (checked属性代表为是否选中返回TRUE或FALSE)<br />32.单选按钮组(单选按钮的名称必须相同):取单选按钮组的长度<font style="background-color: rgb(255, 255, 153);">document.forms[0].groupName.length</font><br />33.单选按钮组判断是否被选中也是用checked.<br />34.下拉列表框的值:document.forms[0].selectName.options[n].value (n有时用下拉列表框名称加上.selectedIndex来确定被选中的值)<br />35.字符串的定义:var myString = new String(&quot;This is lightsword&quot;);<br />36.字符串转成大写:string.toUpperCase(); 字符串转成小写:string.toLowerCase();<br />37.返回字符串2在字符串1中出现的位置:String1.indexOf(&quot;String2&quot;)!=-1则说明没找到.<br />38.取字符串中指定位置的一个字符:StringA.charAt(9);<br />39.取出字符串中指定起点和终点的子字符串:stringA.substring(2,6);<br />40.数学函数:Math.PI(返回圆周率),Math.SQRT2(返回开方),Math.max(value1,value2)返回两个数中的最在值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四舍五入函数,Math.floor(Math.random()*(n+1))返回随机数<br />41.定义日期型变量:<font style="background-color: rgb(255, 255, 153);">var today = new Date();</font><br />42.日期函数列表:dateObj.getTime()得到时间,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期几,dateObj.getHours()得到小时,dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTime(value)设置时间,dateObj.setYear(val)设置年,dateObj.setMonth(val)设置月,dateObj.setDate(val)设置日,dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置分,dateObj.setSeconds(val)设置秒&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [注意:此日期时间从0开始计]<br />43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames[&quot;frameName&quot;].ObjFuncVarName,frameName.ObjFuncVarName<br />44.parent代表父亲对象,top代表最顶端对象<br />45.打开子窗口的父窗口为:opener<br />46.表示当前所属的位置:this<br />47.当在超链接中调用JS函数时用:(Javascript:)来开头后面加函数名<br />48.在老的浏览器中不执行此JS:&lt;!--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //--&gt;<br />49.引用一个文件式的JS:&lt;script type=&quot;text/Javascript&quot; src=&quot;aaa.js&quot;&gt;&lt;/script&gt;<br />50.指定在不支持脚本的浏览器显示的HTML:&lt;noscript&gt;&lt;/noscript&gt;<br />51.当超链和ONCLICK事件都有时,则老版本的浏览器转向a.html,否则转向b.html.例:&lt;a href=&quot;a.html&quot; onclick=&quot;location.href='b.html';return false&quot;&gt;dfsadf&lt;/a&gt;<br />52.JS的内建对象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,ReferenceError,RegExp,String,SyntaxError,TypeError,URIError<br />53.JS中的换行:\n<br />54.窗口全屏大小:&lt;script&gt;function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;&lt;/script&gt;<br />55.JS中的all代表其下层的全部元素</font></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><font size="2">56.JS中的焦点顺序:<font style="background-color: rgb(255, 255, 153);">document.getElementByid(&quot;表单元素&quot;).tabIndex = 1</font><br />57.innerHTML的值是表单元素的值:如&lt;p id=&quot;para&quot;&gt;&quot;how are &lt;em&gt;you&lt;/em&gt;&quot;&lt;/p&gt;,则innerHTML的值就是:how are &lt;em&gt;you&lt;/em&gt;<br />58.innerTEXT的值和上面的一样,只不过不会把&lt;em&gt;这种标记显示出来.<br />59.contentEditable可设置元素是否可被修改,isContentEditable返回是否可修改的状态.<br />60.isDisabled判断是否为禁止状态.disabled设置禁止状态<br />61.<font style="background-color: rgb(255, 255, 153);">length取得长度,返回整型数值</font><br />62.addBehavior()是一种JS调用的外部函数文件其扩展名为.htc<br />63.<font style="background-color: rgb(255, 255, 153);">window.focus()使当前的窗口在所有窗口之前.</font><br />64.blur()指失去焦点.与FOCUS()相反.<br />65.select()指元素为选中状态.<br />66.<font style="background-color: rgb(255, 255, 153);">防止用户对文本框中输入文本:onfocus=&quot;this.blur()&quot;</font><br />67.取出该元素在页面中出现的数量:<font style="background-color: rgb(255, 255, 153);">document.all.tags(&quot;div(或其它HTML标记符)&quot;).length</font><br />68.JS中分为两种窗体输出:模态和非模态.window.showModaldialog(),window.showModeless()<br />69.状态栏文字的设置:window.status='文字',默认的状态栏文字设置:window.defaultStatus = '文字.';<br />70.添加到收藏夹:<font style="background-color: rgb(255, 255, 153);">external.AddFavorite(&quot;</font></font><a href="http://www.xrss.cn&quot;,&quot;jaskdlf/" style="text-decoration: none; color: rgb(0, 0, 0);"><font size="2" style="background-color: rgb(255, 255, 153);">http://www.xrss.cn&quot;,&quot;jaskdlf</font></a><font size="2"><font style="background-color: rgb(255, 255, 153);">&quot;);<br /></font>71.JS中遇到脚本错误时不做任何操作:<font style="background-color: rgb(255, 255, 153);">window.onerror = doNothing</font>; 指定错误句柄的语法为:window.onerror = handleError;<br />72.JS中指定当前打开窗口的父窗口:window.opener,支持opener.opener...的多重继续.<br />73.JS中的self指的是当前的窗口<br />74.JS中状态栏显示内容:window.status=&quot;内容&quot;<br />75.<font style="background-color: rgb(255, 255, 153);">JS中的top指的是框架集中最顶层的框架</font><br />76.JS中关闭当前的窗口:window.close();<br />77.JS中提出是否确认的框:if(confirm(&quot;Are you sure?&quot;)){alert(&quot;ok&quot;);}else{alert(&quot;Not Ok&quot;);}<br />78.JS中的窗口重定向:window.navigate(&quot;</font><a href="http://www.sina.com.cn/" style="text-decoration: none; color: rgb(0, 107, 173);"><font size="2">http://www.sina.com.cn</font></a><font size="2">&quot;);<br />79.JS中的打印:<font style="background-color: rgb(255, 255, 153);">window.print()</font><br />80.JS中的提示输入框:window.prompt(&quot;message&quot;,&quot;defaultReply&quot;);<br />81.JS中的窗口滚动条:window.scroll(x,y)<br />82.JS中的窗口滚动到位置:window.scrollby<br />83.JS中设置时间间隔:setInterval(&quot;expr&quot;,msecDelay)或setInterval(funcRef,msecDelay)或setTimeout<br />84.JS中的模态显示在IE4+行,在NN中不行:showModalDialog(&quot;URL&quot;[,arguments][,features]);<br />85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue=&quot;we really like you and hope you will stay longer.&quot;;}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.onbeforeunload=verifyClose;<br />86.当窗体第一次调用时使用的文件句柄:onload()<br />87.当窗体关闭时调用的文件句柄:onunload()<br />88.window.location的属性: protocol(http:),hostname(</font><a href="http://www.example.com),port(80),host(www.example.com/a/a.html%22),hash(%22#giantGizmo" style="text-decoration: none; color: rgb(0, 0, 0);"><font size="2">www.example.com),port(80),host(www.example.com:80),pathname(&quot;/a/a.html&quot;),hash(&quot;#giantGizmo</font></a><font size="2">&quot;,指跳转到相应的锚记),href(全部的信息)<br />89.<font style="background-color: rgb(255, 255, 153);">window.location.reload()刷新当前页面.<br /></font>89-1<font style="background-color: rgb(255, 255, 153);">.parent.location.reload()刷新父亲对象（用于框架）</font><br />89-2.<font style="background-color: rgb(255, 255, 153);">opener.location.reload()刷新父窗口对象（用于单开窗口）<br /></font>89-3<font style="background-color: rgb(255, 255, 153);">.top.location.reload()刷新最顶端对象（用于多开窗口）<br /></font>90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回第几页,也可以使用访问过的URL)<br />91.<font style="background-color: rgb(255, 255, 153);">document.write()不换行的输出,document.writeln()换行输出</font><br />92.document.body.noWrap=true;防止链接文字折行.<br />93.变量名.charAt(第几位),取该变量的第几位的字符.<br />94.&quot;abc&quot;.charCodeAt(第几个),返回第几个字符的ASCii码值.<br />95.字符串连接:string.concat(string2),或用+=进行连接<br />96.变量.indexOf(&quot;字符&quot;,起始位置),返回第一个出现的位置(从0开始计算)<br />97.string.lastIndexOf(searchString[,startIndex])最后一次出现的位置.<br />98.string.match(regExpression),判断字符是否匹配.<br />99.string.replace(regExpression,replaceString)替换现有字符串.<br />100.string.split(分隔符)返回一个数组存储值.<br />101.string.substr(start[,length])取从第几位到指定长度的字符串.<br />102.string.toLowerCase()使字符串全部变为小写.<br />103.string.toUpperCase()使全部字符变为大写.<br />104.parseInt(string[,radix(代表进制)])强制转换成整型.<br />105.parseFloat(string[,radix])强制转换成浮点型.<br />106.<font style="background-color: rgb(255, 255, 153);">isNaN(变量):测试是否为数值型.<br /></font>107.定义常量的关键字:<font style="background-color: rgb(255, 255, 153);">const,</font>定义变量的关键字:var</font></p></span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/48.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=48</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=48&amp;key=6c156f16</trackback:ping></item><item><title>Ie和firefox的Js区别 </title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/47.htm</link><pubDate>Thu, 25 Feb 2010 18:17:28 +0800</pubDate><guid>http://zihan.cn/post/47.htm</guid><description><![CDATA[<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;" class="Apple-style-span"><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 18px; font-size: 12px;">1.<span class="Apple-converted-space">&nbsp;</span><font color="#000000">对象</font>问题<span class="Apple-converted-space">&nbsp;</span><br />1.1 Form对象<span class="Apple-converted-space">&nbsp;</span><br />现有问题：<br />现有<font color="#000000">代码</font>这获得form对象通过document.forms(&quot;formName&quot;)，这样使用在IE 能接受，MF 不能。<br />解决<font color="#000000">方法：</font><br />改用 作为下<a style="text-decoration: none; color: rgb(0, 0, 0);" name="baidusnap4"></a>标运算。改为document.forms[&quot;formName&quot;]<br />备注<br />上述的改用 作为下标运算中的formName是id而name<br /><br />1.2<span class="Apple-converted-space">&nbsp;</span><font color="#000000">HTML</font>对象<span class="Apple-converted-space">&nbsp;</span><br />现有问题：<br />在 IE 中，HTML 对象的 ID 可以作为 document 的下</span><span style="line-height: 18px; font-size: 12px;">属对象变量名直接使用。在 MF 中不能。<br />document.all(&quot;itemName&quot;)或者document.all(&quot;itemId&quot;)<br />解决方法：<br />使用对象ID作为对象变量名<br />document.getElementById(&quot;itemId&quot;)<br />备注<br />document.all是IE自定义的方法，所以请大家尽量不使用。<br />还有一种方式，在IE和MF都可以使用<br />var f = document.forms[&quot;formName &quot;];<br />var o = f. itemId;<br /><br />1.3 DIV对象<span class="Apple-converted-space">&nbsp;</span><br />现有问题：<br />在 IE 中，DIV对象可以使用ID作为对象变量名直接使用。在 MF 中不能。<br />DivId.style.display = &quot;none&quot;<br />解决方法：<br />document.getElementById(&quot;DivId&quot;).style.display = &quot;none&quot;<br />备注<br />获得对象的方法不管是不是DIV对象，都使用getElementById方法。参见1.2<br /><br /><br />1.4 关于frame<span class="Apple-converted-space">&nbsp;</span><br />现有问题<br />在 IE中 可以用window.testFrame取得该frame，mf中不行<br />解决方法<br />在frame的使用方面MF和IE的最主要的区别<a style="text-decoration: none; color: rgb(0, 0, 0);" name="baidusnap6"></a>是：<br />如果在frame标签中书写了以下属性：<br /><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 />另外，在mf和ie中都可以使用window.top.document.getElementById(&quot;frameId&quot;)来访问frame标签<br />并且可以通过window.top.document.getElementById(&quot;testFrame&quot;).src = 'xx.htm'来切换frame的内容<br />也都可以通过window.top.frameName.location = 'xx.htm'来切换frame的内容<br /><br />1.5 窗口<span class="Apple-converted-space">&nbsp;</span><br />现有问题<br />IE中可以通过showModalDialog和showModelessDialog打开模态和非模态窗口，但是MF不支持。<br />解决办法<br />直接使用window.open(pageURL,name,parameters)方式打开新窗口。<br />如果需要传递参数，可以使用frame或者iframe。<br /><br />2. 总结<span class="Apple-converted-space">&nbsp;</span><br />2.1 在JS中定义各种对象变量名时，尽量使用id，避免使用name。<span class="Apple-converted-space">&nbsp;</span><br />在 IE 中，HTML 对象的 ID 可以作为 document 的下属对象变量名直接使用。在 MF 中不能，所以在平常使用时请尽量使用id，避免只使用name，而不使用id。<br /><br />2.2 变量名与某 HTML 对象 id 相同的问题<span class="Apple-converted-space">&nbsp;</span><br />现有问题<br />在 MF 中，因为对象 id 不作为 HTML 对象的名称，所以可以使用与 HTML 对象 id 相同的变量名，IE 中不能。<br />解决方法<br />在声明变量时，一律加上 var ，以避免歧义，这样在 IE 中亦可正常运行。<br />此外，最好不要取与 HTML 对象 id 相同的变量名，以减少错误。<br /><br /><br />1. document.all<br />&nbsp;&nbsp; Firefox可以兼容document.all， 但会生成一条警告。可以用getElementById(&quot;*&quot;) 或者 getElementByTagName(&quot;*)来代替<br />&nbsp;&nbsp; 不过对于document.all.length等属性，则完全不兼容。<br />2. parentElement<br />&nbsp;&nbsp; 这个也不兼容。比方说， obj.parentElement.name 则应改成 obj.parentNode.attributes.getNamedItem(&quot;name&quot;).nodeValue （不知道如何写得更简洁些）<br />3. event<br />&nbsp;&nbsp; W3C不支持windows.event<br />&nbsp;&nbsp; 比方说:<span class="Apple-converted-space">&nbsp;</span><br />在IE里面<br />&nbsp;&nbsp; &nbsp;&nbsp; &lt;div class=&quot;menu&quot; id=&quot;menu&quot; ōnclick=&quot;onMenuClick(); &quot;&gt;.....&lt;/div&gt;<br />&nbsp;&nbsp; function onMenuClick()<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; collapseMenu(event.srcElement);<br />&nbsp;&nbsp; }<span class="Apple-converted-space">&nbsp;</span><br /><font color="#000000">工作</font>正常。不过在Firefox中，则改成：<br /><br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div class=&quot;menu&quot; id=&quot;menu&quot; ōnclick=&quot;onMenuClick(event); &quot;&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; function onMenuClick(evt)<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(evt == null)<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; evt = window.event; // For IE<br />&nbsp;&nbsp; &nbsp;&nbsp; var srcElement = evt.srcElement? evt.srcElement : evt.target; // IE使用srcElement, 而Firefox使用target<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; collapseMenu(srcElement);<br />}<br /><br /><br />IE和FIREFOX在解析<font color="#000000">CSS</font>方面的区别<br />对高度的解析<span class="Apple-converted-space">&nbsp;</span><br />IE：将根据内容的高度变化，包括未定义高度的图片内容，即使定义了高度，当内容超过高度时，将使用实际高度<span class="Apple-converted-space">&nbsp;</span><br /><br />Firefox：没有定义高度时，如果内容中包括了图片内容，MF的高度解析是根据印刷标准，这样就会造成和实际内容高度不符合的情况；当定义了高度，但是内容超过高度时，内容会超出定义的高度，但是区域使用的样式不会变化，造成样式错位。<span class="Apple-converted-space">&nbsp;</span><br /><br />结论：大家在可以确定内容高度的情况下最好定义高度，如果真的没有办法定义高度，最好不用使用边框样式，否则样式肯定会出现混乱！<span class="Apple-converted-space">&nbsp;</span><br /><br />img对象alt和title的解析<span class="Apple-converted-space">&nbsp;</span><br />alt：当照片不存在或者load错误时的提示；<span class="Apple-converted-space">&nbsp;</span><br /><br />title：照片的tip说明。<span class="Apple-converted-space">&nbsp;</span><br /><br />在IE中如果没有定义title，alt也可以作为img的tip使用，但是在MF中，两者完全按照标准中的定义使用<span class="Apple-converted-space">&nbsp;</span><br /><br />结论：大家在定义img对象时，最后将alt和title对象都写全，保证在各种浏览器中都能正常使用<span class="Apple-converted-space">&nbsp;</span><br /><br />其他的细节差别<span class="Apple-converted-space">&nbsp;</span><br /><br />当你在写css的时候，特别是用float: left（或right）排列一窜图片时，会发现在firefox里面正常而IE里面有问题。无论你用margin:0,还是border: 0来约束，都无济于事。<span class="Apple-converted-space">&nbsp;</span><br /><br />其实这里还有另外一个问题，就是IE对于空格的处理，firefox是忽略的而IE对于块与块之间的空格是处理的。也就是说一个div结束后要紧接着一个div写，中间不要有回车或者空格。不然也许会有问题，比如3px的偏差，而且这个原因很难发现。<span class="Apple-converted-space">&nbsp;</span><br /><br />非常不走运的是我又碰到了这样的问题，多个img标签连着，然后定义的float: left，希望这些图片可以连起来。但是结果在firefox里面正常而IE里面显示的每个img都相隔了3px。我把标签之间的空格都删除都没有作用。<span class="Apple-converted-space">&nbsp;</span><br /><br />后来的解决方法是在img外面套li，并且对li定义margin: 0，这样就解决了IE和firefox的显示偏差。IE对于一些模型的解释会产生很多错误问题，只有多多尝试才能发现原因。<span class="Apple-converted-space">&nbsp;</span><br /><br />这只是一些简单的区别,在做布局和CSS设计时候可以综合考虑,但最为有效与简单的解决兼容问题还是用TABLE表格,表格在兼容性方面有着不错的表现.<span class="Apple-converted-space">&nbsp;</span><br /><br />另外在模版的JS设计的时候也需要考虑两者对代码的兼容,以下是对IE与FIREFOX中JS的一些测试:<span class="Apple-converted-space">&nbsp;</span><br /><br />以下以 IE 代替<span class="Apple-converted-space">&nbsp;</span><font color="#000000">Internet</font><span class="Apple-converted-space">&nbsp;</span>Explorer，以 MF 代替 Mozilla Firefox<span class="Apple-converted-space">&nbsp;</span><br /><br />1. document.form.item 问题<br />(1)现有问题：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 现有代码中存在许多 document.formName.item(&quot;itemName&quot;) 这样的语句，不能<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 在 MF 下运行<br />(2)解决方法：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 改用 document.formName.elements[&quot;elementName&quot;]<br />(3)其它<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 参见 2<span class="Apple-converted-space">&nbsp;</span><br /><br />2. 集合类对象问题<br />(1)现有问题：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 现有代码中许多集合类对象取用时使用 ()，IE 能接受，MF 不能。<br />(2)解决方法：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 改用 [] 作为下标运算。如：document.forms(&quot;formName&quot;) 改为<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.forms[&quot;formName&quot;]。<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 又如：document.getElementsByName(&quot;inputName&quot;)(1) 改为<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.getElementsByName(&quot;inputName&quot;)[1]<br />(3)其它<span class="Apple-converted-space">&nbsp;</span><br /><br />3. window.event<br />(1)现有问题：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 使用 window.event 无法在 MF 上运行<br />(2)解决方法：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MF 的 event 只能在事件发生的现场使用，此问题暂无法解决。可以这样变通：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 原代码(可在IE中运行)：<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;input type=&quot;button&quot; name=&quot;someButton&quot; value=&quot;提交&quot;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; onclick=&quot;javascrīpt:gotoSubmit()&quot;/&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; ...<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;scrīpt language=&quot;javascrīpt&quot;&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; function gotoSubmit() {<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ...<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; alert(window.event); // use window.event<br />&nbsp;&nbsp; &nbsp;&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; &lt;/scrīpt&gt;<span class="Apple-converted-space">&nbsp;</span><br /><br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 新代码(可在IE和MF中运行)：<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;input type=&quot;button&quot; name=&quot;someButton&quot; value=&quot;提交&quot;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; onclick=&quot;javascrīpt:gotoSubmit(event)&quot;/&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; ...<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;scrīpt language=&quot;javascrīpt&quot;&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; function gotoSubmit(evt) {<br />&nbsp;&nbsp; &nbsp;&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; &nbsp;&nbsp;&nbsp; ...<br />&nbsp;&nbsp; &nbsp;&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; &nbsp;&nbsp;&nbsp; ...<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; }<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;/scrīpt&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 此外，如果新代码中第一行不改，与老代码一样的话(即 gotoSubmit 调用没有给<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 参数)，则仍然只能在IE中运行，但不会出错。所以，这种方案 tpl 部分仍与老<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 代码兼容。<span class="Apple-converted-space">&nbsp;</span><br /><br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ///////////////////////////////////////////////////////////////////////<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 以下来自网友 llihua &nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; //事件处理函数<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; function a(evt) { //FireFox<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; evt = evt? evt: window.event; //IE<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; var srcElem = (evt.target)? evt.target: evt.srcElement;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; //事件处理...<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; }<br /><br />在连接事件处理函数的时候，可以用Inline HTML方式，也可以用Event<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; property方式定义。<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 1、使用Inline HTML方式，如：<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &lt;input type=&quot;radio&quot; name=&quot;radio&quot; value=&quot;1&quot;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; onclick=&quot;javascrīpt:a(event)&quot;&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 注意：<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (1)javascrīpt不能省；<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (2)实参要使用event，形参使用什么都可以(如evt、event等)；<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 2、使用Event property方式绑定事件处理函数，如：<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.form2.radio[0].onclick = a;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // 以上来自网友 llihua &nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ///////////////////////////////////////////////////////////////////////<span class="Apple-converted-space">&nbsp;</span><br /><br />4. HTML 对象的 id 作为对象名的问题<br />(1)现有问题<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 在 IE 中，HTML 对象的 ID 可以作为 document 的下<font color="#000000">属</font>对象变量名直接使用。在<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MF 中不能。<br />(2)解决方法<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 用 getElementById(&quot;idName&quot;) 代替 idName 作为对象变量使用。<span class="Apple-converted-space">&nbsp;</span><br /><br />5. 用idName字符串取得对象的问题<br />(1)现有问题<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 在IE中，利用 eval(idName) 可以取得 id 为 idName 的 HTML 对象，在MF 中不<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 能。<br />(2)解决方法<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 用 getElementById(idName) 代替 eval(idName)。<span class="Apple-converted-space">&nbsp;</span><br /><br />6. 变量名与某 HTML 对象 id 相同的问题<br />(1)现有问题<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 在 MF 中，因为对象 id 不作为 HTML 对象的名称，所以可以使用与 HTML 对象<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; id 相同的变量名，IE 中不能。<br />(2)解决方法<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 在声明变量时，一律加上 var ，以避免歧义，这样在 IE 中亦可正常运行。<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 此外，最好不要取与 HTML 对象 id 相同的变量名，以减少错误。<br />(3)其它<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 参见 问题4<span class="Apple-converted-space">&nbsp;</span><br /><br />7. event.x 与 event.y 问题<br />(1)现有问题<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 在IE 中，event 对象有 x, y 属性，MF中没有。<br />(2)解决方法<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 在MF中，与event.x 等效的是 event.pageX。但event.pageX IE中没有。<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 故采用 event.clientX 代替 event.x。在IE 中也有这个变量。<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; event.clientX 与 event.pageX 有微妙的差别（当整个页面有滚动条的时候），<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 不过大多数时候是等效的。<span class="Apple-converted-space">&nbsp;</span><br /><br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 如果要完全一样，可以稍麻烦些：<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mX = event.x ? event.x : event.pageX;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 然后用 mX 代替 event.x<br />(3)其它<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; event.layerX 在 IE 与 MF 中都有，具体意义有无差别尚未试验。<span class="Apple-converted-space">&nbsp;</span><br /><br /><br />8. 关于frame<br />(1)现有问题<br />&nbsp;&nbsp; &nbsp;&nbsp; 在 IE中 可以用window.testFrame取得该frame，mf中不行<br />(2)解决方法<br />&nbsp;&nbsp; &nbsp;&nbsp; 在frame的使用方面mf和ie的最主要的区别是：<br />&nbsp;&nbsp; &nbsp;&nbsp; 如果在frame标签中书写了以下属性：<br />&nbsp;&nbsp; &nbsp;&nbsp; &lt;frame src=&quot;xx.htm&quot; id=&quot;frameId&quot; name=&quot;frameName&quot; /&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp; 那么ie可以通过id或者name访问这个frame对应的window对象<br />&nbsp;&nbsp; &nbsp;&nbsp; 而mf只可以通过name来访问这个frame对应的window对象<br />&nbsp;&nbsp; &nbsp;&nbsp; 例如如果上述frame标签写在最上层的window里面的htm里面，那么可以这样访问<br />&nbsp;&nbsp; &nbsp;&nbsp; ie： window.top.frameId或者window.top.frameName来访问这个window对象<br />&nbsp;&nbsp; &nbsp;&nbsp; mf： 只能这样window.top.frameName来访问这个window对象<span class="Apple-converted-space">&nbsp;</span><br /><br />&nbsp;&nbsp; &nbsp;&nbsp; 另外，在mf和ie中都可以使用<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; window.top.document.getElementById(&quot;frameId&quot;)<br />&nbsp;&nbsp; &nbsp;&nbsp; 来访问<br />&nbsp;&nbsp; &nbsp;&nbsp; frame标签<br />&nbsp;&nbsp; &nbsp;&nbsp; 并且可以通过<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; window.top.document.getElementById(&quot;testFrame&quot;).src = 'xx.htm'<br />&nbsp;&nbsp; &nbsp;&nbsp; 来切换frame的内容<br />&nbsp;&nbsp; &nbsp;&nbsp; 也都可以通过window.top.frameName.location = 'xx.htm'来切换frame的内容<br />&nbsp;&nbsp; &nbsp;&nbsp; 关于frame和window的描述可以参见bbs的&lsquo;window与frame&rsquo;文章<br />&nbsp;&nbsp; &nbsp;&nbsp; 以及/test/js/test_frame/目录下面的测试<br />&nbsp;&nbsp; &nbsp;&nbsp; ----adun 2004.12.09修改<span class="Apple-converted-space">&nbsp;</span><br /><br />9. 在mf中，自己定义的属性必须getAttribute()取得<br />10.在mf中没有&nbsp;&nbsp; parentElement parement.children&nbsp;&nbsp; 而用<br />&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; parentNode parentNode.childNodes<br />childNodes的下标的含义在IE和MF中不同，MF使用DOM规范，childNodes中会插入空白<br />文本节点。<br />&nbsp;&nbsp; 一般可以通过node.getElementsByTagName()来回避这个问题。<br />当html中节点缺失时，IE和MF对parentNode的解释不同，例如<br />&lt;form&gt;<br />&lt;table&gt;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;input/&gt;<br />&lt;/table&gt;<br />&lt;/form&gt;<br />MF中input.parentNode的值为form, 而IE中input.parentNode的值为空节点<span class="Apple-converted-space">&nbsp;</span><br /><br />MF中节点没有removeNode方法，必须使用如下方法<br />node.parentNode.removeChild(node)<span class="Apple-converted-space">&nbsp;</span><br /><br />11.const 问题<br />&nbsp;&nbsp; (1)现有问题:<br />&nbsp;&nbsp;&nbsp; 在 IE 中不能使用 const 关键字。如 const constVar = 32;<br />&nbsp;&nbsp;&nbsp; 在IE中这是语法错误。<br />&nbsp;&nbsp; (2)解决方法:<br />&nbsp;&nbsp;&nbsp; 不使用 const ，以 var 代替。<span class="Apple-converted-space">&nbsp;</span><br /><br />12. body 对象<br />MF的body在body标签没有被浏览器完全读入之前就存在，而IE则必须在body完全被读入<br />之后才存在<span class="Apple-converted-space">&nbsp;</span><br /><br />13. url encoding<br />在js中如果书写url就直接写&amp;不要写&amp;例如<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var url = 'xx.jsp?objectName=xx&amp;objectEvent=xxx';<br />frm.action = url那么很有可能url不会被正常显示以至于参数没有正确的传到服务器<br />一般会服务器报错参数没有找到<br />当然如果是在tpl中例外，因为tpl中符合<font color="#000000">xml</font>规范，要求&amp;书写为&amp;<br />一般MF无法识别js中的&amp;<span class="Apple-converted-space">&nbsp;</span><br /><br /><br />14. nodeName 和 tagName 问题<br />&nbsp;&nbsp; (1)现有问题：<br />&nbsp;&nbsp;&nbsp; 在MF中，所有节点均有 nodeName 值，但 textNode 没有 tagName 值。在 IE 中，<br />&nbsp;&nbsp;&nbsp; nodeName 的使用好象<br />&nbsp;&nbsp;&nbsp; 有问题（具体情况没有测试，但我的IE已经死了好几次）。<br />&nbsp;&nbsp; (2)解决方法：<br />&nbsp;&nbsp;&nbsp; 使用 tagName，但应检测其是否为空。<span class="Apple-converted-space">&nbsp;</span><br /><br />15. 元素属性<br />IE下 input.type属性为只读，但是ME下可以修改<span class="Apple-converted-space">&nbsp;</span><br /><br /><br />16. document.getElementsByName() 和 document.all[name] 的问题<br />&nbsp;&nbsp; (1)现有问题：<br />&nbsp;&nbsp;&nbsp; 在 IE 中，getElementsByName()、document.all[name] 均不能用来取得 div 元素<br />&nbsp;&nbsp;&nbsp; （是否还有其它不能取的元素还不知道）。<span class="Apple-converted-space">&nbsp;</span><br /><br />17. DOM 数据岛的问题<br />&nbsp;&nbsp; (1)现有问题<br />&nbsp;&nbsp;&nbsp; 在IE中, &lt;xml&gt;标签具有特殊意义, 可以内含XML DOM, 并能实现与HTML组件的数据<br />&nbsp;&nbsp;&nbsp; 绑定. 在MF中,&lt;xml&gt;则仅仅是一个未知的标记而已.<br />&nbsp;&nbsp;&nbsp; 另外, 对 IE 来说, &lt;xml&gt;实际意味着这里是一个ActiveX对象, 但它却挂在HTML本<br />&nbsp;&nbsp;&nbsp; 身的DOM树下作为一个节点, 因而会对DOM树的遍历造成严重影响.<br />&nbsp;&nbsp; (2)解决方法<br />&nbsp;&nbsp;&nbsp; IE的数据绑定机制是可以用JS来模拟的, 但是太麻烦, 建议不使用数据绑定机制或者<br />&nbsp;&nbsp;&nbsp; 寻找实现这种模拟的库来做. 我们只讨论如何实现DOM的兼容.<br />&nbsp;&nbsp;&nbsp; 在MF中无论已知的HTML标记还是其它符合XML规范的标记, 都是用统一的DOM树来处理<br />&nbsp;&nbsp;&nbsp; 的, 因此, MF事实上完全可以使用DOM数据岛,<span class="Apple-converted-space">&nbsp;</span><font style="background-color: rgb(255, 255, 255);">但与IE小小的不同在于: 在IE中&lt;xml&gt;<br />&nbsp;&nbsp;&nbsp; 是个 DOM document, 而在MF只是 DOM node. 这个差别通常不足为患.</font><br />&nbsp;&nbsp;&nbsp; 但是有一个小小的细节, 为了兼容HTML相当随意的语法, MF无法识别简写的空标记.<br />&nbsp;&nbsp;&nbsp; 如: &lt;xml id=&quot;xx&quot;&gt;&lt;book&gt;&lt;title&gt;xxxx&lt;/title&gt;&lt;content/&gt;&lt;index/&gt;&lt;/book&gt;&lt;/xml&gt;,<br />&nbsp;&nbsp;&nbsp; 这其中&lt;content/&gt;和&lt;index/&gt;是简写形式的, 会使MF无法识别, 应当写成:<br />&nbsp;&nbsp; &nbsp;&nbsp; &lt;content&gt;&lt;/content&gt;&lt;index&gt;&lt;/index&gt;<br />&nbsp;&nbsp;&nbsp; 不过, 我怀疑如果用XHTML, 可能就没有这种问题. 但我还没有试过.<br />&nbsp;&nbsp;&nbsp; 对于IE中&lt;xml&gt;干扰HTML的DOM结构问题, 我现在的方法是处理完毕后把它从HTML的<br />&nbsp;&nbsp;&nbsp; DOM中删除. 不知道还有没有更好的解</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 28px; font-size: 14pt;"><strong>FireFox与IE开发上的一些区别</strong></span></p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;</p><span style="font-size: 12px;"><p style="margin: 1em 0px 0.5em; padding: 0px; line-height: normal;">1. window.event<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：有window.event对象<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：没有window.event对象。可以通过给函数的参数传递event对象。如onmousemove=doMouseMove(event)<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />2. 鼠标当前坐标<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：event.x和event.y。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：event.pageX和event.pageY。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* 通用：两者都有event.clientX和event.clientY属性。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />3. 鼠标当前坐标(加上滚动条滚过的距离)<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：event.offsetX和event.offsetY。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：event.layerX和event.layerY。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />4. 标签的x和y的坐标位置：style.posLeft 和 style.posTop<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：有。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：没有。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* 通用：object.offsetLeft 和 object.offsetTop。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />5. 窗体的高度和宽度<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：document.body.offsetWidth和document.body.offsetHeight。注意：此时页面一定要有body标签。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：window.innerWidth和window.innerHegiht，以及 document.documentElement.clientWidth和 document.documentElement.clientHeight。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* 通用：document.body.clientWidth和document.body.clientHeight。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />6. 添加事件<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：element.attachEvent(&quot;onclick&quot;, func);。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：element.addEventListener(&quot;click&quot;, func, true)。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* 通用：element.onclick=func。虽然都可以使用onclick事件，但是onclick和上面两种方法的效果是不一样的， onclick 只有执行一个过程，而attachEvent和addEventListener执行的是一个过程列表，也就是多个过程。例如： element.attachEvent(&quot;onclick&quot;, func1);element.attachEvent(&quot;onclick&quot;, func2)这样func1和func2都会被执行。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />7. 标签的自定义属性<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：如果给标签div1定义了一个属性value，可以div1.value和div1[&quot;value&quot;]取得该值。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：不能用div1.value和div1[&quot;value&quot;]取。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* 通用：div1.getAttribute(&quot;value&quot;)。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />8. 父节点、子节点和删除节点<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：parentElement、parement.children，element.romoveNode(true)。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：parentNode、parentNode.childNodes，node.parentNode.removeChild(node)。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />9. 画图<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：VML。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：SVG。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />10. CSS：透明<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60)。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF：opacity:0.6。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />11. CSS：圆角<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：不支持圆角。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF： -moz-border-radius:4px，或者-moz-border-radius-topleft:4px;-moz-border- radius-topright:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius- bottomright:4px;。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />12. CSS：双线凹凸边框<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" /><br style="line-height: normal;" />* IE：border:2px outset;。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* FF： -moz-border-top-colors: #d4d0c8 white;-moz-border-left-colors: #d4d0c8 white;-moz-border-right-colors:#404040 #808080;-moz-border-bottom-colors:#404040 #808080;。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />13. 其它（待整理）<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />FireFox: div 设置 margin-left, margin-right 为 auto 时已经居中, IE 不行<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />FireFox: body 设置 text-align 时, div 需要设置 margin: auto(主要是 margin-left,margin-right) 方可居中<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />FireFox: 设置 padding 后, div 会增加 height 和 width, 但 IE 不会, 故需要用 !important 多设一个 height 和 width<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />FireFox: 支持 !important, IE 则忽略, 可用 !important 为　FireFox 特别设置样式<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />div 的垂直居中问题: vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字，就垂直居中了。缺点是要控制内容不要换行<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />cursor: pointer 可以同时在 IE　FireFox 中显示游标手指状， hand 仅 IE 可以<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />FireFox: 链接加边框和背景色，需设置 display: block, 同时设置 float: left 保证不换行。参照 menubar, 给 a 和 menubar 设置高度是为了避免底边显示错位, 若不设 height, 可以在 menubar 中插入一个空格<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />XHTML+CSS兼容性解决方案小集<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />使用XHTML＋CSS构架好处不少，但也确实存在一些问题，不论是因为使用不熟练还是思路不清晰，我就先把一些我遇到的问题写在下面:<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />1.在mozilla firefox和IE中的BOX模型解释不一致导致相差2px解决方法：<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />div{margin:30px!important;margin:28px;}注意这两个margin的顺序一定不能写反，据阿捷的说法!important这个属性IE不能识别，但别的浏览器可以识别。所以在IE下其实解释成这样：<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />div{maring:30px;margin:28px}重复定义的话按照最后一个来执行，所以不可以只写margin:XXpx!important;<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><a style="text-decoration: none; color: rgb(70, 65, 45); font-size: 12px; line-height: 20px;" target="new" href="http://bbs.itokit.com/"><font color="#ffffff" style="line-height: normal;">http://bbs.itokit.com/</font></a><font color="#ffffff" style="line-height: normal;"><span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span>专业的web开发交流论坛</font><span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />2.IE5 和IE6的BOX解释不一致IE5下div{width:300px;margin:0 10px 0 10px;}div的宽度会被解释为300px-10px(右填充)-10px(左填充)最终div的宽度为280px，而在IE6和其他浏览器上宽度则是以300px+10px(右填充)+10px(左填充)=320px来计算的。这时可以做如下修改<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />div{width:300px!important;width　/**/:340px;margin:0　10px　0　10px}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />3.ul标签在Mozilla中默认是有padding值的,而在IE中只有margin有值所以先定义<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />ul{margin:0;padding:0;}就能解决大部分问题<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />4.关于脚本，在xhtml1.1中不支持language属性，只需要把代码改为<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />&lt;script　type=&rdquo;text/javascript&rdquo;&gt;<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />FireFox: div 设置 margin-left, margin-right 为 auto 时已经居中, IE 不行<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />IE怎么不行? .div{width:100px;margin:0 auto;}一样居中<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />FireFox: 设置 padding 后, div 会增加 height 和 width, 但 IE 不会, 故需要用 !important 多设一个 height 和 width<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这个是ie对css盒模型解释有问题造成的,只能迁就它网页教学网<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />FireFox: 支持 !important, IE 则忽略, 可用 !important 为　FireFox 特别设置样式<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />IE7 一样兼容 !important 了<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />cursor: pointer 可以同时在 IE　FireFox 中显示游标手指状， hand 仅 IE 可以<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />pointer是标准的写法,hand是ie6之前版本自行定义的<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />补充:<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />ie6有margin双倍外补丁bug,需要做css .hack<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />firefox更符合标准,在浮动和清除浮动上需要特别注意,而ie容错性比较好<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />ie中height小于一定值(可能是18px)时,可能会在页面上体现不出来,需要overflow:hidden;而firefox可以完全体现height;<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />装好ie6 ie7 ff2大致写个一两个页面就知道大概的不同了,其实不难<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />屏蔽IE浏览器（也就是IE下不显示）<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />*:lang(zh) select {font:12px　!important;} /*FF的专用*/<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />select:empty {font:12px　!important;} /*safari可见*/<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这里select是选择符，根据情况更换。第二句是MAC上safari浏览器独有的。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />仅IE7识别<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />*+html　{&hellip;}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />当面临需要只针对IE7做样式的时候就可以采用这个HACK。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />IE6及IE6以下识别<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />* html　{&hellip;}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这个地方要特别注意很多地主都写了是IE6的HACK其实IE5.x同样可以识别这个HACK。其它浏览器不识别。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />html/**/ &gt;body　select {&hellip;&hellip;}网页教学网<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这句与上一句的作用相同。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />仅IE6不识别<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />select { display /*IE6不识别*/:none;}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这里主要是通过CSS注释分开一个属性与值，流释在冒号前。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />仅IE6与IE5不识别<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />select/**/ { display /*IE6,IE5不识别*/:none;}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这里与上面一句不同的是在选择符与花括号之间多了一个CSS注释。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />仅IE5不识别<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />select/*IE5不识别*/ { display:none;}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这一句是在上一句中去掉了属性区的注释。只有IE5不识别<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />盒模型解决方法<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />selct {width:IE5.x宽度; voice-family :&quot;&quot;}&quot;&quot;; voice-family:inherit; width:正确宽度;}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />盒模型的清除方法不是通过!important来处理的。这点要明确。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />清除浮动<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />select:after {content:&quot;.&quot;; display:block; height:0; clear:both; visibility:hidden;}<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />在Firefox中，当子级都为浮动时，那么父级的高度就无法完全的包住整个子级，那么这时用这个清除浮动的HACK来对父级做一次定义，那么就可以解决这个问题 。<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" /><br style="line-height: normal;" />截字省略号<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />select { -o-text-overflow:ellipsis; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; }<span style="line-height: 18px;" class="Apple-converted-space"><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal;" />这个是在越出长度后会自行的截掉多出部分的文字，并以省略号结尾，很好的一个技术。只是目前Firefox并不支持。</p><p style="margin: 1em 0px 0.5em; padding: 0px; line-height: normal;">&nbsp;</p><p style="margin: 1em 0px 0.5em; padding: 0px; line-height: normal;">&nbsp;</p><div class="gg_as"><h3 style="margin: 0px; padding: 0px;">XHTML：非IE浏览器里对style.height赋值无效的问题</h3><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">今天我在做多页面MDI脚本控件（MzMultiPage），在IE等浏览器里都已经测试通过没有任何问题，但是在Mozilla、Firefox、Netscape里测试时问题就来了，我的多页面是在页面里用到了 iframe，这些 iframe 初始的 style.height 都是0，而在加载页面之后，iframe 就会自适应被加载的页面高度，我是通过 iframe.style.height=300 这样撑起 iframe 的高度，这样处理在IE系列浏览器里没有任何问题，但在非IE浏览器里死活行不通，通过跟踪，发现根本没有把这个 300 赋给 style.height，最后测试出来竟然必须给定赋值的单位，即 iframe.style.height=&quot;300px&quot;，这样赋值才有效，没有单位的赋值无效，郁闷了我老半天！</p><p style="margin: 1em 0px 0.5em; padding: 0px;">说明一下环境：我用的是XHTML的DTD，即在页面头上是：&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a style="text-decoration: none; color: rgb(0, 0, 0);" href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&quot;&gt;，也正是因为这个 XHTML1.dtd 才导致非IE浏览器里的 style.height 有问题。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">另外透露一点知识：在Netsacpe里的iframe，若通过设置 style.display=&quot;none&quot; 隐藏这个 iframe 的话，会把通过脚本动态写入到 iframe 的HTML&ldquo;冲掉&rdquo;。所以在 Netscape 里的 iframe 若有脚本写入HTML又需要动态隐藏/显示这个 iframe 的操作时建议你使用 style.width=&quot;0px&quot; style.height=&quot;0px&quot;; 这样的方式隐藏！</p></div></span></span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/47.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=47</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=47&amp;key=6048377f</trackback:ping></item><item><title>IE与Firefox的CSS兼容大全</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/46.htm</link><pubDate>Thu, 25 Feb 2010 18:15:51 +0800</pubDate><guid>http://zihan.cn/post/46.htm</guid><description><![CDATA[<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;" class="Apple-style-span"><p style="margin: 1em 0px 0.5em; padding: 0px;">CSS对浏览器器的兼容性具有很高的价值，通常情况下IE和Firefox存在很大的解析差异，这里介绍一下兼容要点。<br /><br /><span style="line-height: 27px; font-size: 18px; color: red; font-family: 黑体;">常见兼容问题：</span><br /><br />1.DOCTYPE 影响 CSS 处理<br /><br />2.FF: div 设置 margin-left, margin-right 为 auto 时已经居中, IE 不行<br /><br />3.FF: body 设置 text-align 时, div 需要设置 margin: auto(主要是 margin-left,margin-right) 方可居中<br /><br />4.FF: 设置 padding 后, div 会增加 height 和 width, 但 IE 不会, 故需要用 !important 多设一个 height 和 width<br /><br />5.FF: 支持 !important, IE 则忽略, 可用 !important 为 FF 特别设置样式<br /><br />6.div 的垂直居中问题: vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字，就垂直居中了缺点是要控制内容不要换行<br /><br />7.cursor: pointer 可以同时在 IE FF 中显示游标手指状， hand 仅 IE 可以</p><p style="margin: 1em 0px 0.5em; padding: 0px;">　　8.FF: 链接加边框和背景色，需设置 display: block, 同时设置 float: left 保证不换行。参照 menubar, 给 a 和 menubar 设置高度是为了避免底边显示错位, 若不设 height, 可以在 menubar 中插入一个空格。<br /><br />9.在mozilla firefox和IE中的BOX模型解释不一致导致相差2px解决方法：</p><div class="code">div{margin:30px!important;margin:28px;}</div>注意这两个margin的顺序一定不能写反，据阿捷的说法!important这个属性IE不能识别，但别的浏览器可以识别。所以在IE下其实解释成这样：<div class="code">div{maring:30px;margin:28px}</div>重复定义的话按照最后一个来执行，所以不可以只写margin:XXpx!important;<br /><br />10.IE5 和IE6的BOX解释不一致<br />IE5下<div class="code">div{width:300px;margin:0 10px 0 10px;}</div>div的宽度会被解释为300px-10px(右填充)-10px(左填充)最终div的宽度为280px，而在IE6和其他浏览器上宽度则是以300px+10px(右填充)+10px(左填充)=320px来计算的。这时我们可以做如下修改<div class="code">div{width:300px!important;width /**/:340px;margin:0 10px 0 10px}</div>关于这个/**/是什么我也不太明白，只知道IE5和firefox都支持但IE6不支持，如果有人理解的话，请告诉我一声，谢了！：）<br /><br />11.ul标签在Mozilla中默认是有padding值的,而在IE中只有margin有值所以先定义<div class="code">ul{margin:0;padding:0;}</div><p style="margin: 1em 0px 0.5em; padding: 0px;">　　就能解决大部分问题</p><p style="margin: 1em 0px 0.5em; padding: 0px;">　　<span style="line-height: 27px; font-size: 18px; color: red; font-family: 黑体;">注意事项：</span><br /><br />1、float的div一定要闭合。<br /><br />例如：(其中floatA、floatB的属性已经设置为float:left;)</p><div class="code">&lt;#div id=&quot;floatA&quot; &gt;&lt;/#div&gt;<br />&lt;#div id=&quot;floatB&quot; &gt;&lt;/#div&gt;<br />&lt;#div id=&quot;NOTfloatC&quot; &gt;&lt;/#div&gt;</div><p style="margin: 1em 0px 0.5em; padding: 0px;">　　这里的NOTfloatC并不希望继续平移，而是希望往下排。<br />这段代码在IE中毫无问题，问题出在FF。原因是NOTfloatC并非float标签，必须将float标签闭合。<br />在</p><div class="code">&lt;#div class=&quot;floatB&quot;&gt;&lt;/#div&gt;<br />&lt;#div class=&quot;NOTfloatC&quot;&gt;&lt;/#div&gt;</div><p style="margin: 1em 0px 0.5em; padding: 0px;">　　之间加上</p><div class="code">&lt;#div class=&quot;clear&quot;&gt;&lt;/#div&gt;</div><p style="margin: 1em 0px 0.5em; padding: 0px;">　　这个div一定要注意声明位置，一定要放在最恰当的地方，而且必须与两个具有float属性的div同级，之间不能存在嵌套关系，否则会产生异常。<br />并且将clear这种样式定义为为如下即可：</p><div class="code">.clear{<br />clear:both;}</div><p style="margin: 1em 0px 0.5em; padding: 0px;">　　此外，为了让高度能自动适应，要在wrapper里面加上overflow:hidden;<br />当包含float的box的时候，高度自动适应在IE下无效，这时候应该触发IE的layout私有属性(万恶的IE啊！)用zoom:1;可以做到，这样就达到了兼容。<br />例如某一个wrapper如下定义：</p><div class="code">.colwrapper{<br />overflow:hidden;<br />zoom:1;<br />margin:5px auto;}</div><p style="margin: 1em 0px 0.5em; padding: 0px;"><br />2、margin加倍的问题。<br /><br />设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。<br />解决方案是在这个div里面加上display:inline;<br />例如：</p><div class="code">&lt;#div id=&quot;imfloat&quot;&gt;&lt;/#div&gt;</div><p style="margin: 1em 0px 0.5em; padding: 0px;"><br />相应的css为</p><div class="code">#IamFloat{<br />float:left;<br />margin:5px;/*IE下理解为10px*/<br />display:inline;/*IE下再理解为5px*/}</div><p style="margin: 1em 0px 0.5em; padding: 0px;"><br />3、关于容器的包涵关系<br /><br />很多时候，尤其是容器内有平行布局，例如两、三个float的div时，宽度很容易出现问题。在IE中，外层的宽度会被内层更宽的div挤破。一定要用Photoshop或者Firework量取像素级的精度。<br /><br />4、关于高度的问题<br /><br />如果是动态地添加内容，高度最好不要定义。浏览器可以自动伸缩，然而如果是静态的内容，高度最好定好。（似乎有时候不会自动往下撑开，不知道具体怎么回事）<br /><br />5、最狠的手段 - !important;<br /><br />如果实在没有办法解决一些细节问题,可以用这个方法.FF对于&quot;!important&quot;会自动优先解析,然而IE则会忽略.如下</p><div class="code">.tabd1{<br />background:url(/res/images/up/tab1.gif) no-repeat 0px 0px !important; /*Style for FF*/<br />background:url(/res/images/up/tab1.gif) no-repeat 1px 0px; /* Style for IE */}</div><p style="margin: 1em 0px 0.5em; padding: 0px;">　　值得注意的是，一定要将xxxx !important 这句放置在另一句之上，上面已经提过</p></span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/46.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=46</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=46&amp;key=aac51063</trackback:ping></item><item><title>js获取页面宽和高</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/45.htm</link><pubDate>Thu, 25 Feb 2010 18:14:24 +0800</pubDate><guid>http://zihan.cn/post/45.htm</guid><description><![CDATA[<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;" class="Apple-style-span">网页可见区域宽：document.body.clientWidth;<span class="Apple-converted-space">&nbsp;</span><br />网页可见区域高：document.body.clientHeight;<span class="Apple-converted-space">&nbsp;</span><br />网页可见区域高：document.body.offsetWidth&nbsp;&nbsp; (包括边线的宽);<br />网页可见区域高：document.body.offsetHeight (包括边线的宽);<br />网页正文全文宽：document.body.scrollWidth;<span class="Apple-converted-space">&nbsp;</span><br />网页正文全文高：document.body.scrollHeight;<span class="Apple-converted-space">&nbsp;</span><br />网页被卷去的高：document.body.scrollTop;<span class="Apple-converted-space">&nbsp;</span><br />网页被卷去的左：document.body.scrollLeft;<span class="Apple-converted-space">&nbsp;</span><br />网页正文部分上：window.screenTop;<span class="Apple-converted-space">&nbsp;</span><br />网页正文部分左：window.screenLeft;<span class="Apple-converted-space">&nbsp;</span><br />屏幕分辨率的高：window.screen.height;<span class="Apple-converted-space">&nbsp;</span><br />屏幕分辨率的宽：window.screen.width;<span class="Apple-converted-space">&nbsp;</span><br />屏幕可用工作区高度：window.screen.availHeight;<span class="Apple-converted-space">&nbsp;</span><br />屏幕可用工作区宽度：window.screen.availWidth;</span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/45.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=45</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=45&amp;key=26047ca5</trackback:ping></item><item><title>Javascript的IE和Firefox兼容性汇编</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/44.htm</link><pubDate>Thu, 25 Feb 2010 18:10:12 +0800</pubDate><guid>http://zihan.cn/post/44.htm</guid><description><![CDATA[<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;" class="Apple-style-span"><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);"><span style="line-height: 21px; color: rgb(0, 0, 0);">微软关于IE、Firefox、Opera和Safari的JavaScript兼容性研究曾经发表过一份草案,可以点击下载《</span><a style="text-decoration: none; color: rgb(0, 0, 0);" href="http://wiki.ecmascript.org/lib/exe/fetch.php?id=resources%3Aresources&amp;cache=cache&amp;media=resources:jscriptdeviationsfromes3.pdf"><span style="line-height: 21px; color: rgb(0, 0, 0);">JScript Deviations from ES3</span></a><span style="line-height: 21px; color: rgb(0, 0, 0);">》</span></span><span style="line-height: 21px; color: rgb(0, 0, 0);">&nbsp;以下为网上的一些搜集和整理(FF代表Firefox)</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;<span style="line-height: 21px; color: rgb(0, 0, 255);">集合类对象问题</span><br />现有代码中存在许多 document.form.item(&quot;itemName&quot;) 这样的语句，不能在 FF 下运行<br />解决方法：<br />改用 document.form.elements[&quot;elementName&quot;]<br />说明:IE下,可以使用()或[]获取集合类对象;Firefox下,只能使用[]获取集合类对象.<br />解决方法:统一使用[]获取集合类对象.</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br /><span style="line-height: 21px; color: rgb(0, 0, 255);">window.event</span><br />现有问题：<br />使用 window.event 无法在 FF 上运行<br />解决方法：<br />FF 的 event 只能在事件发生的现场使用，此问题暂无法解决。可以这样变通：<br />原代码(可在IE中运行)：<br /><span style="line-height: 21px; background-color: rgb(192, 192, 192);">&lt;input type=&quot;button&quot; name=&quot;someButton&quot; value=&quot;提交&quot; onclick=&quot;javascript:gotoSubmit()&quot;/&gt;<br />&lt;script language=&quot;javascript&quot;&gt;<br />&nbsp;&nbsp;&nbsp; function gotoSubmit() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(window.event);&nbsp;&nbsp;&nbsp; // use window.event<br />&nbsp;&nbsp;&nbsp; }<br />&lt;/script&gt;</span><br />新代码(可在IE和FF中运行)：<br /><span style="line-height: 21px; background-color: rgb(192, 192, 192);">&lt;input type=&quot;button&quot; name=&quot;someButton&quot; value=&quot;提交&quot; onclick=&quot;javascript:gotoSubmit(event)&quot;/&gt;<br />&lt;script language=&quot;javascript&quot;&gt;<br />&nbsp;&nbsp; function gotoSubmit(e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e = e? e : (window.event ? window.event : null);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(e);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />&nbsp; }<br />&lt;/script&gt;</span><br />此外，如果新代码中第一行不改，与老代码一样的话（即 gotoSubmit 调用没有给参数），则仍然只能在IE中运行，但不会出错。所以，这种方案 tpl 部分仍与老代码兼容。</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">HTML 对象的 id 作为对象名的问题</span><br />现有问题：<br />在 IE 中，HTML 对象的 ID 可以作为 document 的下属对象变量名直接使用。在 FF 中不能。<br />解决方法：<br />用 getElementById(&quot;idName&quot;) 代替 idName 作为对象变量使用。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">用idName字符串取得对象的问题<br />现有问题：<br />在IE中，利用 eval(idName) 可以取得 id 为 idName 的 HTML 对象，在FF 中不能。<br />解决方法：<br />用 getElementById(idName) 代替 eval(idName)。</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">变量名与某 HTML 对象 id 相同的问题</span><br />现有问题：<br />在 FF 中，因为对象 id 不作为 HTML 对象的名称，所以可以使用与 HTML 对象 id 相同的变量名，IE 中不能。<br />解决方法：<br />在声明变量时，一律加上 var ，以避免歧义，这样在 IE 中亦可正常运行。<br />此外，最好不要取与 HTML 对象 id 相同的变量名，以减少错误。</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">event.x 与 event.y 问题</span><br />现有问题：<br />在IE 中，event 对象有 x, y 属性，FF中没有。<br />解决方法：<br />在FF中，与event.x 等效的是 event.pageX。但event.pageX IE中没有。<br />故采用 event.clientX 代替 event.x。在IE 中也有这个变量。<br />event.clientX 与 event.pageX 有微妙的差别（当整个页面有滚动条的时候），不过大多数时候是等效的。<br />如果要完全一样，可以稍麻烦些：<br />mX = event.x ? event.x : event.pageX;<br />然后用 mX 代替 event.x<br />其它：<br />event.layerX 在 IE 与 FF 中都有，具体意义有无差别尚未试验。</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">关于frame</span><br />现有问题：<br />在 IE中 可以用window.testFrame取得该frame，FF中不行<br />解决方法：<br />在frame的使用方面FF和ie的最主要的区别是：<br />如果在frame标签中书写了以下属性：<br />&lt;frame src=&quot;/xx.htm&quot; id=&quot;frameId&quot; name=&quot;frameName&quot; /&gt;<br />那么ie可以通过id或者name访问这个frame对应的window对象<br />而FF只可以通过name来访问这个frame对应的window对象<br />例如如果上述frame标签写在最上层的window里面的htm里面，那么可以这样访问<br />IE： window.top.frameId或者window.top.frameName来访问这个window对象<br />FF： 只能这样window.top.frameName来访问这个window对象<br />另外，在FF和ie中都可以使用window.top.document.getElementById(&quot;frameId&quot;)来访问frame标签<br />并且可以通过window.top.document.getElementById(&quot;testFrame&quot;).src = 'xx.htm'来切换frame的内容<br />也都可以通过window.top.frameName.location = 'xx.htm'来切换frame的内容</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">父结点的问题</span><br />在FF中没有 parentElement parentElement.children&nbsp; 而用 parentNode parentNode.childNodes<br />childNodes的下标的含义在IE和FF中不同，FF使用DOM规范，childNodes中会插入空白文本节点。<br />一般可以通过node.getElementsByTagName()来回避这个问题。当html中节点缺失时，IE和FF对parentNode的解释不同，例如<br /><span style="line-height: 21px; background-color: rgb(192, 192, 192);">&lt;form&gt;<br />&lt;table&gt;<br />&nbsp; &lt;input/&gt;<br />&lt;/table&gt;<br />&lt;/form&gt;</span><br />FF中input.parentNode的值为form, 而IE中input.parentNode的值为空节点<br />FF中节点没有removeNode方法，必须使用如下方法 node.parentNode.removeChild(node)</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">const 问题</span><br />现有问题：<br />在 IE 中不能使用 const 关键字。如 const constVar = 32; 在IE中这是语法错误。<br />解决方法：<br />不使用 const ，以 var 代替。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">body 对象<br />FF的body在body标签没有被浏览器完全读入之前就存在，而IE则必须在body完全被读入之后才存在</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">URLencoding</span><br />在js中如果书写url就直接写&amp;不要写&amp;例如var url = 'xx.jsp?objectName=xx&amp;objectEvent=xxx';<br />frm.action = url那么很有可能url不会被正常显示以至于参数没有正确的传到服务器<br />一般会服务器报错参数没有找到<br />当然如果是在tpl中例外，因为tpl中符合xml规范，要求&amp;书写为&amp;<br />一般FF无法识别js中的&amp;</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">nodeName 和 tagName 问题</span><br />现有问题：<br />在FF中，所有节点均有 nodeName 值，但 textNode 没有 tagName 值。在 IE 中，nodeName 的使用好象有问题<br />解决方法：<br />使用 tagName，但应检测其是否为空。</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">元素属性</span><br />IE下 input.type属性为只读，但是FF下可以修改<br />document.getElementsByName() 和 document.all[name] 的问题<br />在 IE 中，getElementsByName()、document.all[name] 均不能用来取得多个具有相同name的div 元素集合。</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">兼容firefox的 outerHTML，FF中没有outerHtml的方法</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; background-color: rgb(192, 192, 192);">if (window.HTMLElement) {<br />&nbsp; HTMLElement.prototype.__defineSetter__(&quot;outerHTML&quot;,function(sHTML) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var r=this.ownerDocument.createRange();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r.setStartBefore(this);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var df=r.createContextualFragment(sHTML);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.parentNode.replaceChild(df,this);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return sHTML;<br />&nbsp;&nbsp;&nbsp; });</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; background-color: rgb(192, 192, 192);">&nbsp;&nbsp;&nbsp; HTMLElement.prototype.__defineGetter__(&quot;outerHTML&quot;,function() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var attr;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var attrs=this.attributes;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var str=&quot;&lt;&quot;+this.tagName.toLowerCase();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (var i=0;i&lt;attrs.length;i++) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; attr=attrs[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(attr.specified)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str+=&quot; &quot;+attr.name+'=&quot;'+attr.value+'&quot;';<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; background-color: rgb(192, 192, 192);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!this.canHaveChildren)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return str+&quot;&gt;&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return str+&quot;&gt;&quot;+this.innerHTML+&quot;&lt;/&quot;+this.tagName.toLowerCase()+&quot;&gt;&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; background-color: rgb(192, 192, 192);">&nbsp;&nbsp; HTMLElement.prototype.__defineGetter__(&quot;canHaveChildren&quot;,function() {<br />&nbsp;&nbsp;&nbsp;&nbsp; switch(this.tagName.toLowerCase()) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;area&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;base&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;basefont&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;col&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;frame&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;hr&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;img&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;br&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;input&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;isindex&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;link&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;meta&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case &quot;param&quot;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br />&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp; return true;<br />&nbsp;&nbsp; });<br />}</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br /><span style="line-height: 21px; color: rgb(0, 0, 255);">自定义属性问题</span><br />说明:IE下,可以使用获取常规属性的方法来获取自定义属性,也可以使用getAttribute()获取自定义属性;FF下,只能使用getAttribute()获取自定义属性.<br />解决方法:统一通过getAttribute()获取自定义属性.</p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;<br /><span style="line-height: 21px; color: rgb(0, 0, 255);">event.srcElement问题</span><br />说明:IE下,even对象有srcElement属性,但是没有target属性;Firefox下,even对象有target属性,但是没有srcElement属性.<br />解决方法:使用obj(obj = event.srcElement ? event.srcElement : event.target;)来代替IE下的event.srcElement或者Firefox下的event.target.</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br /><span style="line-height: 21px; color: rgb(0, 0, 255);">window.location.href问题</span><br />说明:IE或者Firefox2.0.x下,可以使用window.location或window.location.href;Firefox1.5.x下,只能使用window.location.<br />解决方法:使用window.location来代替window.location.href.</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br /><span style="line-height: 21px; color: rgb(0, 0, 255);">模态和非模态窗口问题</span><br />说明:IE下,可以通过showModalDialog和showModelessDialog打开模态和非模态窗口;Firefox下则不能.<br />解决方法:直接使用window.open(pageURL,name,parameters)方式打开新窗口<br />如果需要将子窗口中的参数传递回父窗口,可以在子窗口中使用window.opener来访问父窗口. 例如：var parWin = window.opener; parWin.document.getElementById(&quot;Aqing&quot;).value = &quot;Aqing&quot;;</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; color: rgb(0, 0, 255);">事件委托方法</span><br />IE：document.body.onload = inject; //Function inject()在这之前已被实现<br />FF：document.body.onload = inject();<br />如果要加传递参数，可以做个闭包<br /><span style="line-height: 21px; background-color: rgb(192, 192, 192);">(function(arg){</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; background-color: rgb(192, 192, 192);">&nbsp;&nbsp; document.body.onload=function(){inject(arg);};</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><span style="line-height: 21px; background-color: rgb(192, 192, 192);">})(arg)</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;">innerText在IE中能正常工作，但是innerText在FireFox中却不行.<br />解决方法:<br /><span style="line-height: 21px; background-color: rgb(192, 192, 192);">if(navigator.appName.indexOf(&quot;Explorer&quot;) &gt; -1){<br />&nbsp;&nbsp;&nbsp; document.getElementById('element').innerText = &quot;my text&quot;;<br />} else{<br />&nbsp;&nbsp;&nbsp; document.getElementById('element').textContent = &quot;my text&quot;;<br />}</span></p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br /><span style="line-height: 21px; color: rgb(0, 0, 255);">FF中类似 obj.style.height = imgObj.height 的语句无效</span><br />解决方法：<br />obj.style.height = imgObj.height + 'px';</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br /><span style="line-height: 21px; color: rgb(0, 0, 255);">IE,FF以及其它浏览器对于 table 标签的操作都各不相同，在ie中不允许对table和tr的innerHTML赋值，使用js增加一个tr时，使用appendChile方法也不管用</span><br />解决方法：<br />//向table追加一个空行：<br />var row = otable.insertRow(-1);<br />var cell = document.createElement(&quot;td&quot;);<br />cell.innerHTML = &quot; &quot;;<br />cell.className = &quot;XXXX&quot;;<br />row.appendChild(cell);</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br /><span style="line-height: 21px; color: rgb(255, 0, 0);">样式部分</span><br />-----------------------------------------------------------------------------------------------------------<br />cursor:hand VS cursor:pointer<br />FF不支持hand，但ie支持pointer<br />解决方法: 统一使用pointer</p><p style="margin: 1em 0px 0.5em; padding: 0px;">padding 问题<br />padding 5px 4px 3px 1px FireFox无法解释简写,<br />必须改成 padding-top:5px; padding-right:4px; padding-bottom:3px; padding-left:1px;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">消除ulol等列表的缩进时<br />样式应写成:list-style:none;margin:0px;padding:0px;<br />其中margin属性对IE有效，padding属性对FireFox有效</p><p style="margin: 1em 0px 0.5em; padding: 0px;">CSS透明<br />IE：filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60)<br />FF：opacity:0.6</p><p style="margin: 1em 0px 0.5em; padding: 0px;">CSS圆角<br />IE：不支持圆角<br />FF： -moz-border-radius:4px，或者-moz-border-radius-topleft:4px;-moz-border- radius-topright:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius- bottomright:4px;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">CSS双线凹凸边框<br />IE：border:2px outset;<br />FF： -moz-border-top-colors: #d4d0c8 white;-moz-border-left-colors: #d4d0c8 white;-moz-border-right-colors:#404040 #808080;-moz-border-bottom-colors:#404040 #808080;</p></span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/44.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=44</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=44&amp;key=17e5d760</trackback:ping></item><item><title>js cookie 的操作</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/43.htm</link><pubDate>Thu, 25 Feb 2010 15:58:55 +0800</pubDate><guid>http://zihan.cn/post/43.htm</guid><description><![CDATA[<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;" class="Apple-style-span">cookie概述<br />在上一节，曾经利用一个不变的框架来存储购物栏数据，而商品显示页面是不断变化的，尽管这<br /><br />样能达到一个模拟全局变量的功能，但并不严谨。例如在导航框架页面内右击，单击快捷菜单中<br /><br />的【刷新】命令，则所有的JavaScript变量都会丢失。因此，要实现严格的跨页面全局变量，这<br /><br />种方式是不行的，JavaScript中的另一个机制：cookie，则可以达到真正全局变量的要求。<br />cookie是浏览器提供的一种机制，它将document对象的cookie属性提供给JavaScript。可以由<br /><br />JavaScript对其进行控制，而并不是JavaScript本身的性质。cookie是存于用户硬盘的一个文件<br /><br />，这个文件通常对应于一个域名，当浏览器再次访问这个域名时，便使这个cookie可用。因此，<br /><br />cookie可以跨越一个域名下的多个网页，但不能跨越多个域名使用。<br />不同的浏览器对cookie的实现也不一样，但其性质是相同的。例如在Windows 2000以及Windows<span class="Apple-converted-space">&nbsp;</span><br /><br />xp中，cookie文件存储于documents and settings\userName\cookie\文件夹下。通常的命名格<br /><br />式为：userName@domain.txt。<br />cookie机制将信息存储于用户硬盘，因此可以作为全局变量，这是它最大的一个优点。它可以用<br /><br />于以下几种场合。<br />保存用户登录状态。例如将用户id存储于一个cookie内，这样当用户下次访问该页面时就不需<br /><br />要重新登录了，现在很多论坛和社区都提供这样的功能。cookie还可以设置过期时间，当超过时<br /><br />间期限后，cookie就会自动消失。因此，系统往往可以提示用户保持登录状态的时间：常见选项<br /><br />有一个月、三个月、一年等。<br />跟踪用户行为。例如一个天气预报网站，能够根据用户选择的地区显示当地的天气情况。如果<br /><br />每次都需要选择所在地是烦琐的，当利用了cookie后就会显得很人性化了，系统能够记住上一次<br /><br />访问的地区，当下次再打开该页面时，它就会自动显示上次用户所在地区的天气情况。因为一切<br /><br />都是在后台完成，所以这样的页面就像为某个用户所定制的一样，使用起来非常方便。<br />定制页面。如果网站提供了换肤或更换布局的功能，那么可以使用cookie来记录用户的选项，<br /><br />例如：背景色、分辨率等。当用户下次访问时，仍然可以保存上一次访问的界面风格。<br />创建购物车。正如在前面的例子中使用cookie来记录用户需要购买的商品一样，在结账的时候<br /><br />可以统一提交。例如淘宝网就使用cookie记录了用户曾经浏览过的商品，方便随时进行比较。<br />当然，上述应用仅仅是cookie能完成的部分应用，还有更多的功能需要全局变量。cookie的缺点<br /><br />主要集中于安全性和隐私保护。主要包括以下几种：<br />cookie可能被禁用。当用户非常注重个人隐私保护时，他很可能禁用浏览器的cookie功能；<br />cookie是与浏览器相关的。这意味着即使访问的是同一个页面，不同浏览器之间所保存的<br /><br />cookie也是不能互相访问的；<br />cookie可能被删除。因为每个cookie都是硬盘上的一个文件，因此很有可能被用户删除；<br />cookie安全性不够高。所有的cookie都是以纯文本的形式记录于文件中，因此如果要保存用户<br /><br />名密码等信息时，最好事先经过加密处理。<br />设置cookie<br />每个cookie都是一个名/值对，可以把下面这样一个字符串赋值给document.cookie：<br />document.cookie=&quot;userId=828&quot;;<br />如果要一次存储多个名/值对，可以使用分号加空格（; ）隔开，例如：<br />document.cookie=&quot;userId=828; userName=hulk&quot;;<br />在cookie的名或值中不能使用分号（;）、逗号（,）、等号（=）以及空格。在cookie的名中做<br /><br />到这点很容易，但要保存的值是不确定的。如何来存储这些值呢？方法是用escape()函数进行编<br /><br />码，它能将一些特殊符号使用十六进制表示，例如空格将会编码为&ldquo;20%&rdquo;，从而可以存储于<br /><br />cookie值中，而且使用此种方案还可以避免中文乱码的出现。例如：<br />document.cookie=&quot;str=&quot;+escape(&quot;I love ajax&quot;);<br />相当于：<br />document.cookie=&quot;str=I%20love%20ajax&quot;;<br />当使用escape()编码后，在取出值以后需要使用unescape()进行解码才能得到原来的cookie值，<br /><br />这在前面已经介绍过。<br />尽管document.cookie看上去就像一个属性，可以赋不同的值。但它和一般的属性不一样，改变<br /><br />它的赋值并不意味着丢失原来的值，例如连续执行下面两条语句：<br />document.cookie=&quot;userId=828&quot;;<br />document.cookie=&quot;userName=hulk&quot;;<br />这时浏览器将维护两个cookie，分别是userId和userName，因此给document.cookie赋值更像执<br /><br />行类似这样的语句：<br />document.addCookie(&quot;userId=828&quot;);<br />document.addCookie(&quot;userName=hulk&quot;);<br />事实上，浏览器就是按照这样的方式来设置cookie的，如果要改变一个cookie的值，只需重新赋<br /><br />值，例如：<br />document.cookie=&quot;userId=929&quot;;<br />这样就将名为userId的cookie值设置为了929。<br /><br />获取cookie的值<br />下面介绍如何获取cookie的值。cookie的值可以由document.cookie直接获得：<br />var strCookie=document.cookie;<br />这将获得以分号隔开的多个名/值对所组成的字符串，这些名/值对包括了该域名下的所有cookie<br /><br />。例如：<br />&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;<br />&lt;!--<br />document.cookie=&quot;userId=828&quot;;<br />document.cookie=&quot;userName=hulk&quot;;<br />var strCookie=document.cookie;<br />alert(strCookie);<br />//--&gt;<br />&lt;/script&gt;<br />图7.1显示了输出的cookie值。由此可见，只能够一次获取所有的cookie值，而不能指定cookie<br /><br />名称来获得指定的值，这正是处理cookie值最麻烦的一部分。用户必须自己分析这个字符串，来<br /><br />获取指定的cookie值，例如，要获取userId的值，可以这样实现：<br />&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;<br />&lt;!--<br />//设置两个cookie<br />document.cookie=&quot;userId=828&quot;;<br />document.cookie=&quot;userName=hulk&quot;;<br />//获取cookie字符串<br />var strCookie=document.cookie;<br />//将多cookie切割为多个名/值对<br />var arrCookie=strCookie.split(&quot;; &quot;);<br />var userId;<br />//遍历cookie数组，处理每个cookie对<br />for(var i=0;i&lt;arrCookie.length;i++){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var arr=arrCookie[i].split(&quot;=&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//找到名称为userId的cookie，并返回它的值<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(&quot;userId&quot;==arr[0]){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; userId=arr[1];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br />alert(userId);<br />//--&gt;<br />&lt;/script&gt;<br />这样就得到了单个cookie的值<br /><br />用类似的方法，可以获取一个或多个cookie的值，其主要的技巧仍然是字符串和数组的相关操作<br /><br />。<br /><br />给cookie设置终止日期<br />到现在为止，所有的cookie都是单会话cookie，即浏览器关闭后这些cookie将会丢失，事实上这<br /><br />些cookie仅仅是存储在内存中，而没有建立相应的硬盘文件。<br />在实际开发中，cookie常常需要长期保存，例如保存用户登录的状态。这可以用下面的选项来实<br /><br />现：<br />document.cookie=&quot;userId=828; expires=GMT_String&quot;;<br />其中GMT_String是以GMT格式表示的时间字符串，这条语句就是将userId这个cookie设置为<br /><br />GMT_String表示的过期时间，超过这个时间，cookie将消失，不可访问。例如：如果要将cookie<br /><br />设置为10天后过期，可以这样实现：<br />&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;<br />&lt;!--<br />//获取当前时间<br />var date=new Date();<br />var expireDays=10;<br />//将date设置为10天以后的时间<br />date.setTime(date.getTime()+expireDays*24*3600*1000);<br />//将userId和userName两个cookie设置为10天后过期<br />document.cookie=&quot;userId=828; userName=hulk; expire=&quot;+date.toGMTString();<br />//--&gt;<br />&lt;/script&gt;<br /><br />删除cookie<br />为了删除一个cookie，可以将其过期时间设定为一个过去的时间，例如：<br />&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;<br />&lt;!--<br />//获取当前时间<br />var date=new Date();<br />//将date设置为过去的时间<br />date.setTime(date.getTime()-10000);<br />//将userId这个cookie删除<br />document.cookie=&quot;userId=828; expire=&quot;+date.toGMTString();<br />//--&gt;<br />&lt;/script&gt;<br />指定可访问cookie的路径<br />默认情况下，如果在某个页面创建了一个cookie，那么该页面所在目录中的其他页面也可以访问<br /><br />该cookie。如果这个目录下还有子目录，则在子目录中也可以访问。例如在<br /><br />www.xxxx.com/html/a.html中所创建的cookie，可以被www.xxxx.com/html/b.html或<br /><br />www.xxx.com/ html/ some/c.html所访问，但不能被www.xxxx.com/d.html访问。<br />为了控制cookie可以访问的目录，需要使用path参数设置cookie，语法如下：<br />document.cookie=&quot;name=value; path=cookieDir&quot;;<br />其中cookieDir表示可访问cookie的目录。例如：<br />document.cookie=&quot;userId=320; path=/shop&quot;;<br />就表示当前cookie仅能在shop目录下使用。<br />如果要使cookie在整个网站下可用，可以将cookie_dir指定为根目录，例如：<br />document.cookie=&quot;userId=320; path=/&quot;;<br /><br /><br />指定可访问cookie的主机名<br />和路径类似，主机名是指同一个域下的不同主机，例如：www.google.com和gmail.google.com就<br /><br />是两个不同的主机名。默认情况下，一个主机中创建的cookie在另一个主机下是不能被访问的，<br /><br />但可以通过domain参数来实现对其的控制，其语法格式为：<br />document.cookie=&quot;name=value; domain=cookieDomain&quot;;<br />以google为例，要实现跨主机访问，可以写为：<br />document.cookie=&quot;name=value;domain=.google.com&quot;;<br />这样，所有google.com下的主机都可以访问该cookie。<br /><br /><br />综合示例：构造通用的cookie处理函数<br />cookie的处理过程比较复杂，并具有一定的相似性。因此可以定义几个函数来完成cookie的通用<br /><br />操作，从而实现代码的复用。下面列出了常用的cookie操作及其函数实现。<br />1．添加一个cookie：addCookie(name,value,expireHours)<br />该函数接收3个参数：cookie名称，cookie值，以及在多少小时后过期。这里约定expireHours为<br /><br />0时不设定过期时间，即当浏览器关闭时cookie自动消失。该函数实现如下：<br />&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;<br />&lt;!--<br />function addCookie(name,value,expireHours){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var cookieString=name+&quot;=&quot;+escape(value);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//判断是否设置过期时间<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(expireHours&gt;0){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var date=new Date();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date.setTime(date.getTime+expireHours*3600*1000);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cookieString=cookieString+&quot;; expire=&quot;+date.toGMTString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.cookie=cookieString;<br />}<br />//--&gt;<br />&lt;/script&gt;<br />2．获取指定名称的cookie值：getCookie(name)<br />该函数返回名称为name的cookie值，如果不存在则返回空，其实现如下：<br />&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;<br />&lt;!--<br />function getCookie(name){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var strCookie=document.cookie;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var arrCookie=strCookie.split(&quot;; &quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(var i=0;i&lt;arrCookie.length;i++){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var arr=arrCookie[i].split(&quot;=&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(arr[0]==name)return arr[1];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return &quot;&quot;;<br />}<br />//--&gt;<br />&lt;/script&gt;<br />3．删除指定名称的cookie：deleteCookie(name)<br />该函数可以删除指定名称的cookie，其实现如下：<br />&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;<br />&lt;!--<br />function deleteCookie(name){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var date=new Date();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; date.setTime(date.getTime()-10000);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.cookie=name+&quot;=v; expire=&quot;+date.toGMTString();<br />}<br />//--&gt;<br />&lt;/script&gt; <br /></span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/43.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=43</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=43&amp;key=7e4b9a06</trackback:ping></item><item><title>JS 关于浏览器之间 scrollHeight offsetHeight (比如 iframe自适应高度时...) </title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/42.htm</link><pubDate>Thu, 25 Feb 2010 15:57:35 +0800</pubDate><guid>http://zihan.cn/post/42.htm</guid><description><![CDATA[<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;" class="Apple-style-span"><p style="margin: 1em 0px 0.5em; padding: 0px;">关于clientHeight、offsetHeight、scrollHeight</p><p style="margin: 1em 0px 0.5em; padding: 0px;">window.screen.availWidth&nbsp;&nbsp;&nbsp;&nbsp; 返回当前屏幕宽度(空白空间)&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />window.screen.availHeight&nbsp;&nbsp;&nbsp;&nbsp; 返回当前屏幕高度(空白空间)&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />window.screen.width&nbsp;&nbsp;&nbsp;&nbsp; 返回当前屏幕宽度(分辨率值)&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />window.screen.height&nbsp;&nbsp;&nbsp;&nbsp; 返回当前屏幕高度(分辨率值)&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />window.document.body.offsetHeight;&nbsp;&nbsp;&nbsp;&nbsp; 返回当前网页高度&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />window.document.body.offsetWidth;&nbsp;&nbsp;&nbsp;&nbsp; 返回当前网页宽度&nbsp;&nbsp;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">我们这里说说四种浏览器对 document.body 的 clientHeight、offsetHeight 和 scrollHeight 的解释。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">这四种浏览器分别为IE（Internet Explorer）、NS（Netscape）、Opera、FF（FireFox）。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">clientHeight<br />大家对 clientHeight 都没有什么异议，都认为是内容可视区域的高度，也就是说页面浏览器中可以看到内容的这个区域的高度，一般是最后一个工具条以下到状态栏以上的这个区域，与页面内容无关。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">offsetHeight<br />IE、Opera 认为 offsetHeight = clientHeight + 滚动条 + 边框。<br />NS、FF 认为 offsetHeight 是网页内容实际高度，可以小于 clientHeight。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">scrollHeight<br />IE、Opera 认为 scrollHeight 是网页内容实际高度，可以小于 clientHeight。<br />NS、FF 认为 scrollHeight 是网页内容高度，不过最小值是 clientHeight。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">简单地说<br />clientHeight 就是透过浏览器看内容的这个区域高度。<br />NS、FF 认为 offsetHeight 和 scrollHeight 都是网页内容高度，只不过当网页内容高度小于等于 clientHeight 时，scrollHeight 的值是 clientHeight，而 offsetHeight 可以小于 clientHeight。<br />IE、Opera 认为 offsetHeight 是可视区域 clientHeight 滚动条加边框。scrollHeight 则是网页内容实际高度。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">同理<br />clientWidth、offsetWidth 和 scrollWidth 的解释与上面相同，只是把高度换成宽度即可。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">=======================================================================</p><p style="margin: 1em 0px 0.5em; padding: 0px;">clientHeight与offsetHeight的区别</p><p style="margin: 1em 0px 0.5em; padding: 0px;">许多文章已经介绍了clientHeight和offsetHeight的区别，就是clientHeight的值不包括scrollbar的高度，而offsetHeight的值包括了scrollbar的高度。然而，clientHeight和offsetHeight的值到底由什么组成的呢？如何计算这两个数的值？</p><p style="margin: 1em 0px 0.5em; padding: 0px;">1. clientHeight和offsetHeight的值由什么决定？</p><p style="margin: 1em 0px 0.5em; padding: 0px;">假如我们有以下的DIV，主要显示的文字为&quot;This is the main body of DIV&quot;。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">如上图所示，clientHeight的值由DIV内容的实际高度和CSS中的padding值决定，而offsetHeight的值由DIV内容的实际高度，CSS中的padding值，scrollbar的高度和DIV的border值决定；至于CSS中的margin值，则不会影响clientHeight和offsetHeight的值。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">2. CSS中的Height值对clientHeight和offsetHeight有什么影响？</p><p style="margin: 1em 0px 0.5em; padding: 0px;">首先，我们看一下CSS中Height定义的是什么的高度。如在本文最后部分&ldquo;APPENDIX示例代码&rdquo;（注：以下称为&ldquo;示例代码&rdquo;）中，innerDIVClass的Height值设定为50px，在IE下计算出来的值如下所示。也就是说，在IE里面，CSS中的Height值定义了DIV包括padding在内的高度（即offsetHeight的值）；在Firefox里面，CSS中的Height值只定义的DIV实际内容的高度，padding并没有包括在这个值里面(70 = 50 + 10 * 2)。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">in IE:<span class="Apple-converted-space">&nbsp;</span><br />innerDiv.clientHeight: 46<br />innerDiv.offsetHeight: 50<br />outerDiv.clientHeight: 0<br />outerDiv.offsetHeight: 264</p><p style="margin: 1em 0px 0.5em; padding: 0px;">in Firfox:<br />innerDiv.clientHeight: 70<br />innerDiv.offsetHeight: 74<br />outerDiv.clientHeight: 348<br />outerDiv.offsetHeight: 362</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br />在上面的示例中，也许你会很奇怪，为什么在IE里面outerDiv.clientHeight的值为0。那是因为示例代码中，没有定义outerDIVClass的Height值，这时，在IE里面，则clientHeight的值是无法计算的。同样，在示例代码中，如果将innerDIVClass中的Height值去年，则innerDIV.clientHeight的值也为0。(注：在Firefox下不存在这种情况)。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">如果CSS中Height值小于DIV要显示内容的高度的时候呢（当CSS中没有定义overflow的行为时）？在IE里面，整个clientHeight（或者offsetHeight）的值并没有影响，DIV会自动被撑大；而在Firefox里面，DIV是不会被撑开的。如在示例代码中，将innerDivClass的Height值设为0，则计算结果如下所示。IE里面的DIV被撑开，其clientHeight值等于内容的高度与padding*2的和；而Firefox里面，文字将溢出DIV的边界，其clientHeight值正好是padding值的两倍。</p><p style="margin: 1em 0px 0.5em; padding: 0px;">In IE:<br />innerDiv.clientHeight: 38<br />innerDiv.offsetHeight: 42<br />outerDiv.clientHeight: 0<br />outerDiv.offsetHeight: 256</p><p style="margin: 1em 0px 0.5em; padding: 0px;">In Firefox:<br />innerDiv.clientHeight: 20<br />innerDiv.offsetHeight: 24<br />outerDiv.clientHeight: 298<br />outerDiv.offsetHeight: 312</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br />APPENDIX　示例代码</p><p style="margin: 1em 0px 0.5em; padding: 0px;">&lt;html&gt;<br />&lt;head&gt;<br />&lt;style type=&quot;text/css&quot;&gt;......<br />.innerDivClass<br />{...}{...}{...}{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color: red;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin: 37px;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; padding: 10px;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border: 2px solid #000000;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; height: 50px;</p><p style="margin: 1em 0px 0.5em; padding: 0px;"><br />}<br />.outerDivClass<br />{...}{...}{...}{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; padding: 100px;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; margin: 200px;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; border: 7px solid #000000;<br />}<br />&lt;/style&gt;</p><p style="margin: 1em 0px 0.5em; padding: 0px;">&lt;script&gt;......<br />function checkClientHeight()<br />......{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var innerDiv = document.getElementById(&quot;innerDiv&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var outerDiv = document.getElementById(&quot;outerDiv&quot;);</p><p style="margin: 1em 0px 0.5em; padding: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result.innerHTML = &quot;innerDiv.clientHeight: &quot; + innerDiv.clientHeight + &quot;&lt;br /&gt;&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result.innerHTML += &quot;innerDiv.offsetHeight: &quot; + innerDiv.offsetHeight + &quot;&lt;br /&gt;&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result.innerHTML += &quot;outerDiv.clientHeight: &quot; + outerDiv.clientHeight + &quot;&lt;br /&gt;&quot;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result.innerHTML += &quot;outerDiv.offsetHeight: &quot; + outerDiv.offsetHeight + &quot;&lt;br /&gt;&quot;;<br />}<br />&lt;/script&gt;<br />&lt;/head&gt;<br />&lt;body&gt;<br />&lt;div id=&quot;outerDiv&quot; class=&quot;outerDivClass&quot;&gt;<br />&lt;div class=&quot;innerDivClass&quot; id=&quot;innerDiv&quot;&gt;<br />Hello world.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br />&lt;/div&gt;<br />&lt;/div&gt;<br />&lt;p&gt;&lt;/p&gt;<br />&lt;div id=&quot;result&quot;&gt;<br />&lt;/div&gt;<br />&lt;input type=&quot;button&quot; onclick=&quot;checkClientHeight()&quot; text=&quot;Click Me&quot; Value=&quot;Click Me&quot; /&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</p></span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/42.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=42</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=42&amp;key=9ca8b599</trackback:ping></item><item><title>JS代码在IE和Firefox间的区别</title><author>a@b.com (zihan)</author><link>http://zihan.cn/post/41.htm</link><pubDate>Thu, 25 Feb 2010 15:56:13 +0800</pubDate><guid>http://zihan.cn/post/41.htm</guid><description><![CDATA[<p><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Simsun; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;" class="Apple-style-span"><span style="font-family: verdana,sans-serif; font-size: 14px; line-height: 21px; text-align: left;" class="Apple-style-span"><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpFirst"><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span style="line-height: 21px;">1.<span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">HTML<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对象的</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>id<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">作为对象名的问题</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">HTML<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对象的</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>ID<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">可以作为</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>document<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">的下属对象变量名直接使</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;"><br />FF<span lang="ZH-CN" style="line-height: 21px;">：不支持</span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法：使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">document.getElementById</span><span lang="ZH-CN" style="line-height: 21px; font-family: 宋体;"><span style="line-height: 19px; font-size: small;">替代</span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">document.all</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">2.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">如果控件只有</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">name,</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">没有</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">id,<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">getElementById</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">时</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">:<span class="Apple-converted-space">&nbsp;</span><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：可以找到对象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：返回</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">NULL<br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法：所有控件必须设置</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">ID</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">属性</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">3.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 19px; font-size: small;"><span style="line-height: 19px; font-family: Calibri;">Evel:<br />IE</span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">：支持，</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">利用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>eval(idName)<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">可以取得</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>id<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">为</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>idName<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">的</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>HTML<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">象</span><br /><span style="line-height: 19px; font-size: small;"><span style="line-height: 19px; font-family: Calibri;">FF</span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">：不支持。</span><br /><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">解决方法：统一使用</span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">getElementById(idName)<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">代替</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>eval(idName)</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">。</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">4.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">Event</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：用全局对象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">window.event<br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">event</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">只能在事件发生的现场使</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">用，</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">在调用函数时传入</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">event</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;"><br /><span lang="ZH-CN" style="line-height: 21px;">解决方法：使用之前做一下浏览器类型判断，各用各的。</span></span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">5.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对象名称中美元符号&lsquo;</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">$<span lang="ZH-CN" style="line-height: 21px;">&rsquo;改为使用下划线&lsquo;</span>_<span lang="ZH-CN" style="line-height: 21px;">&rsquo;</span></span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">6.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">集合类对象问题</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;"><br />IE<span lang="ZH-CN" style="line-height: 21px;">：</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">可以使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">()</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">或</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">[]</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">获取集合类对象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：只能使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">[]</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">获取集合类对象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">现有代码中存在许多，不能在</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>FF<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">下运行</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">:</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">统一使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">[]</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">获取集合类对象。</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">document.form.item(&quot;itemName&quot;)<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">这样的语句改为</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">document.form.elements[&quot;elementName&quot;]</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">7.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 19px; font-size: small;"><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">变量名与某</span><span style="line-height: 19px; font-family: Calibri;"><span class="Apple-converted-space">&nbsp;</span>HTML<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">对象</span><span style="line-height: 19px; font-family: Calibri;"><span class="Apple-converted-space">&nbsp;</span>id<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">相同的问题</span><br /><span style="line-height: 19px; font-family: Calibri;">IE</span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">：不能</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">使用与</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>HTML<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>id<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">相同的变量</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">名</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;"><br />FF<span lang="ZH-CN" style="line-height: 21px;">：可以使用</span><br /><span lang="ZH-CN" style="line-height: 21px;">解决方法：</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">在声明变量时，一律加上</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>var<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">，以避免歧义，这样在</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>IE<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">中亦可正常运行。</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">此外，最好不要取与</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>HTML<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>id<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">相同的变量名，以减少错误</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">。</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">8.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 19px; font-size: small;"><span style="line-height: 19px; font-family: Calibri;">Event</span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">定位问题</span><br /><span style="line-height: 19px; font-family: Calibri;">IE</span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">：支持</span><span style="line-height: 19px; font-family: Calibri;">event.x<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">和</span></span><span style="line-height: 19px; font-size: small;"><span style="line-height: 19px; font-family: Calibri;">event.y<br />FF</span><span lang="ZH-CN" style="line-height: 19px; font-family: 宋体;">：支持</span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">event.pageX</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">和</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">event.pageY<br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法，统一使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">event.clientX</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">和</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">event.clientY</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">，但是在</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">中</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">event.clientX<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">与</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>event.pageX<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">有微妙的差别（当整个页面有滚动条的时候），不过大多数时候是等效的</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">。如果要完全一样，可以判断浏览器类型后对应使用。</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">9.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">父结点的问题</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">parentElement parentElement.children<br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">parentNode parentNode.childNodes<br />childNodes</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">的下标的含义在</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">和</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">中不同，</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">DOM</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">规范，</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">childNodes</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">中会插入空白文本节点。一般可以通过</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">node.getElementsByTagName()</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">来回避这个问题。</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /><br /><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">当</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">html</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">中节点缺失时，</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">和</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">parentNode</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">的解释不同，例如</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /><span style="line-height: 21px; background-color: silver;">&lt;form&gt;<br />&lt;table&gt;<br />&nbsp; &lt;input/&gt;<br />&lt;/table&gt;<br />&lt;/form&gt;</span><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">input.parentNode</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">的值为空节点</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">input.parentNode</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">的值为</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">form<span class="Apple-converted-space">&nbsp;</span><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">中节点没有</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">removeNode</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">方法，必须使用如下方法</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>node.parentNode.removeChild(node)</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">10.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 16px; font-size: 10.5pt; font-family: Verdana,sans-serif;">const<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">问题</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">现有问题：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：不支持</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>const<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">关键字。如</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>const constVar = 32;<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">在</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">中这是语法错误。</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：支持</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法：不使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>const<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">，以</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>var<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">代替</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">。</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">11.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">body<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">对</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">象</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;"><br />IE<span lang="ZH-CN" style="line-height: 21px;">：在</span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">body</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">标签完全被读入之后才存</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">在</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;"><br />FF<span lang="ZH-CN" style="line-height: 21px;">：</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">在</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">body</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">标签没有被浏览器完全读入之前就存</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">在</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">12.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">自定义属性问题</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：可以使用获取常规属性的方法来获取自定义属性</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">,</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">也可以使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">getAttribute()</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">获取自定义属性</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：只能使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">getAttribute()</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">获取自定义属性</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">.<br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法：统一通过</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">getAttribute()</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">获取自定义属性</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">13.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 16px; font-size: 10.5pt; font-family: Verdana,sans-serif;">event.srcElement</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">问题</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">even.srcElement<br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">even.target<br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">:</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">使用时判断浏览器类型，各用各的。</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">14.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">模态和非模态窗口</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：支持模态和非模态窗口</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：不支持</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法：直接使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">window.open(pageURL,name,parameters)</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">方式打开新窗</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">口。</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">如果需要将子窗口中的参数传递回父窗口</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">,</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">可以在子窗口中使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">window.opener</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">来访问父窗</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">口。</span></p><p style="margin: 0in 0in 0pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpMiddle"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">15.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">innerText<br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">innerText<br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">：</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">textContent</span></p><p style="margin: 0in 0in 10pt 0.5in; padding: 0px; text-indent: -0.25in;" class="MsoListParagraphCxSpLast"><span style="line-height: 21px;"><span style="line-height: 21px;"><span style="line-height: 19px; font-size: small; font-family: Calibri;">16.</span><span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none;">&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span></span></span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">类似</span><span style="line-height: 16px; font-size: 10.5pt; font-family: Verdana,sans-serif;"><span class="Apple-converted-space">&nbsp;</span>obj.style.height = imgObj.height<span class="Apple-converted-space">&nbsp;</span></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">的语句</span><span style="line-height: 16px; font-size: 10.5pt; font-family: Verdana,sans-serif;"><br />IE</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">：有效</span><span style="line-height: 16px; font-size: 10.5pt; font-family: Verdana,sans-serif;"><br />FF</span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; font-family: 宋体;">：无效</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;"><br /></span><span lang="ZH-CN" style="line-height: 16px; font-size: 10.5pt; color: black; font-family: 宋体;">解决方法：统一使用</span><span style="line-height: 16px; font-size: 10.5pt; color: black; font-family: Verdana,sans-serif;">obj.style.height = imgObj.height + 'px';</span></p></span></span></p>]]></description><category>前端开发</category><comments>http://zihan.cn/post/41.htm#comment</comments><wfw:comment>http://zihan.cn/</wfw:comment><wfw:commentRss>http://zihan.cn/feed.asp?cmt=41</wfw:commentRss><trackback:ping>http://zihan.cn/cmd.asp?act=tb&amp;id=41&amp;key=62b2938f</trackback:ping></item></channel></rss>
