16. document.getElementsByName() ºÍ document.all[name] µÄÎÊÌâ (1)ÏÖÓÐÎÊÌ⣺
ÔÚ IE ÖУ¬getElementsByName()¡¢document.all[name] ¾ù²»ÄÜÓÃÀ´È¡µÃ div ÔªËØ£¨ÊÇ·ñ»¹ÓÐÆäËü²»ÄÜÈ¡µÄÔªËØ»¹²»ÖªµÀ£©¡£
17.¼æÈÝfirefoxµÄ outerHTML£¬FFÖÐûÓÐouterHtmlµÄ·½·¨¡£ if (window.HTMLElement) {
HTMLElement.prototype.__defineSetter__(\ var r=this.ownerDocument.createRange(); r.setStartBefore(this);
var df=r.createContextualFragment(sHTML); this.parentNode.replaceChild(df,this); return sHTML; });
HTMLElement.prototype.__defineGetter__(\ var attr;
var attrs=this.attributes;
var str=\ for (var i=0;i str+=\ } if(!this.canHaveChildren) return str+\ return str+\ }); HTMLElement.prototype.__defineGetter__(\ switch(this.tagName.toLowerCase()) { case \ case \ case \ case \ case \ case \ case \ case \ case \ case \ case \ case \ case \ return false; } return true; }); } 18.×Ô¶¨ÒåÊôÐÔÎÊÌâ ˵Ã÷:IEÏÂ,¿ÉÒÔʹÓûñÈ¡³£¹æÊôÐԵķ½·¨À´»ñÈ¡×Ô¶¨ÒåÊôÐÔ,Ò²¿ÉÒÔʹÓÃgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ;FirefoxÏÂ,Ö»ÄÜʹÓÃgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ. ½â¾ö·½·¨:ͳһͨ¹ýgetAttribute()»ñÈ¡×Ô¶¨ÒåÊôÐÔ. 19.eval(\ÎÊÌâ ˵Ã÷:IEÏÂ,,¿ÉÒÔʹÓÃeval(\»ògetElementById(\À´È¡µÃidΪidNameµÄHTML¶ÔÏó;FirefoxÏÂÖ»ÄÜʹÓÃgetElementById(\À´È¡µÃidΪidNameµÄHTML¶ÔÏó. ½â¾ö·½·¨:ͳһÓÃgetElementById(\À´È¡µÃidΪidNameµÄHTML¶ÔÏó. 20.±äÁ¿ÃûÓëijHTML¶ÔÏóIDÏàͬµÄÎÊÌâ ˵Ã÷:IEÏÂ,HTML¶ÔÏóµÄID¿ÉÒÔ×÷ΪdocumentµÄÏÂÊô¶ÔÏó±äÁ¿ÃûÖ±½ÓʹÓÃ;FirefoxÏÂÔò²»ÄÜ.FirefoxÏÂ,¿ÉÒÔʹÓÃÓëHTML¶ÔÏóIDÏàͬµÄ±äÁ¿Ãû;IEÏÂÔò²»ÄÜ¡£ ½â¾ö·½·¨:ʹÓÃdocument.getElementById(\´úÌædocument.idName.×îºÃ²»ÒªÈ¡HTML¶ÔÏóIDÏàͬµÄ±äÁ¿Ãû,ÒÔ¼õÉÙ´íÎó;ÔÚÉùÃ÷±äÁ¿Ê±,Ò»ÂɼÓÉÏvar,ÒÔ±ÜÃâÆçÒå. 21.constÎÊÌâ ˵Ã÷:FirefoxÏÂ,¿ÉÒÔʹÓÃconst¹Ø¼ü×Ö»òvar¹Ø¼ü×ÖÀ´¶¨Òå³£Á¿;IEÏÂ,Ö»ÄÜʹÓÃvar¹Ø¼ü×ÖÀ´¶¨Òå³£Á¿. ½â¾ö·½·¨:ͳһʹÓÃvar¹Ø¼ü×ÖÀ´¶¨Òå³£Á¿. 22.input.typeÊôÐÔÎÊÌâ ˵Ã÷:IEÏÂinput.typeÊôÐÔΪֻ¶Á;µ«ÊÇFirefoxÏÂinput.typeÊôÐÔΪ¶Áд. 23.window.eventÎÊÌâ ˵Ã÷:window.eventÖ»ÄÜÔÚIEÏÂÔËÐÐ,¶ø²»ÄÜÔÚFirefoxÏÂÔËÐÐ,ÕâÊÇÒòΪFirefoxµÄeventÖ»ÄÜÔÚʼþ·¢ÉúµÄÏÖ³¡Ê¹ÓÃ. ½â¾ö·½·¨: IE: onclick=\... IE&Firefox: 24.event.xÓëevent.yÎÊÌâ ˵Ã÷:IEÏÂ,even¶ÔÏóÓÐx,yÊôÐÔ,µ«ÊÇûÓÐpageX,pageYÊôÐÔ;FirefoxÏÂ,even¶ÔÏóÓÐpageX,pageYÊôÐÔ,µ«ÊÇûÓÐx,yÊôÐÔ. ½â¾ö·½·¨:ʹÓÃmX(mX = event.x ? event.x : event.pageX;)À´´úÌæIEϵÄevent.x»òÕßFirefoxϵÄevent.pageX. 25.event.srcElementÎÊÌâ ˵Ã÷:IEÏÂ,even¶ÔÏóÓÐsrcElementÊôÐÔ,µ«ÊÇûÓÐtargetÊôÐÔ;FirefoxÏÂ,even¶ÔÏóÓÐtargetÊôÐÔ,µ«ÊÇûÓÐsrcElementÊôÐÔ. ½â¾ö·½·¨:ʹÓÃobj(obj = event.srcElement ? event.srcElement : event.target;)À´´úÌæIEϵÄevent.srcElement»òÕßFirefoxϵÄevent.target. 26.window.location.hrefÎÊÌâ ˵Ã÷:IE»òÕßFirefox2.0.xÏÂ,¿ÉÒÔʹÓÃwindow.location»òwindow.location.href;Firefox1.5.xÏÂ,Ö»ÄÜʹÓÃwindow.location. ½â¾ö·½·¨:ʹÓÃwindow.locationÀ´´úÌæwindow.location.href. 27.ģ̬ºÍ·Çģ̬´°¿ÚÎÊÌâ ˵Ã÷:IEÏÂ,¿ÉÒÔͨ¹ýshowModalDialogºÍshowModelessDialog´ò¿ªÄ£Ì¬ºÍ·Çģ̬´°¿Ú;FirefoxÏÂÔò²»ÄÜ. ½â¾ö·½·¨:Ö±½ÓʹÓÃwindow.open(pageURL,name,parameters)·½Ê½´ò¿ªÐ´°¿Ú¡£ Èç ¹ûÐèÒª½«×Ó´°¿ÚÖеIJÎÊý´«µÝ»Ø¸¸´°¿Ú,¿ÉÒÔÔÚ×Ó´°¿ÚÖÐʹÓÃwindow.openerÀ´·ÃÎʸ¸´°¿Ú. ÀýÈ磺var parWin = window.opener; parWin.document.getElementById(\= \ 28.frameÎÊÌâ ÒÔÏÂÃæµÄframeΪÀý£º (1)·ÃÎÊframe¶ÔÏó: IE:ʹÓÃwindow.frameId»òÕßwindow.frameNameÀ´·ÃÎÊÕâ¸öframe¶ÔÏó. Firefox:Ö»ÄÜʹÓÃwindow.frameNameÀ´·ÃÎÊÕâ¸öframe¶ÔÏó. ÁíÍ⣬ÔÚIEºÍFirefoxÖж¼¿ÉÒÔʹÓÃwindow.document.getElementById(\À´·ÃÎÊÕâ¸öframe¶ÔÏó. (2)Çл»frameÄÚÈÝ: ÔÚIEºÍFirefoxÖж¼¿ÉÒÔʹÓÃwindow.document.getElementById(\\»òwindow.frameName.location = \À´Çл»frameµÄÄÚÈÝ. Èç¹ûÐèÒª½«frameÖеIJÎÊý´«»Ø¸¸´°¿Ú£¬¿ÉÒÔÔÚfrmeÖÐʹÓÃparentÀ´·ÃÎʸ¸´°¿Ú¡£ÀýÈ磺parent.document.form1.filename.value=\ 29.bodyÎÊÌâ FirefoxµÄbodyÔÚbody±êǩûÓб»ä¯ÀÀÆ÷ÍêÈ«¶ÁÈë֮ǰ¾Í´æÔÚ£»¶øIEµÄbodyÔò±ØÐëÔÚbody±êÇ©±»ä¯ÀÀÆ÷ÍêÈ«¶ÁÈëÖ®ºó²Å´æÔÚ. ÀýÈ磺 Firefox£º
IE&Firefox£º