2011-03-14 53 views
2

IE8給出了jquery 1.5.1最小化錯誤:Invalid argument,但firefox沒有。jquery-1.5.1.min.js和IE8

誤差來源於此行:W

a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit:a.elem[a.prop]=a.now}}}),d.expr&&d.expr.filters&&(d.expr.filters.animated=function(a){return d.grep(d.timers,function(b){return a===b.elem}).length});var ce=/^t(?:able|d|h)$/i,cf=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?d.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){d.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return d.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(e){}var f=b.ownerDocument,g=f.documentElement;if(!c||!d.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=f.body,i=cg(f),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||d.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||d.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:d.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){d.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return d.offset.bodyOffset(b);d.offset.initialize();var c,e=b.offsetParent,f=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(d.offset.supportsFixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===e&&(l+=b.offsetTop,m+=b.offsetLeft,d.offset.doesNotAddBorder&&(!d.offset.doesAddBorderForTableAndCells||!ce.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),f=e,e=b.offsetParent),d.offset.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;d.offset.supportsFixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},d.offset={initialize:function(){var a=c.body,b=c.createElement("div"),e,f,g,h,i=parseFloat(d.css(a,"marginTop"))||0,j="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";d.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"}),b.innerHTML=j,a.insertBefore(b,a.firstChild),e=b.firstChild,f=e.firstChild,h=e.nextSibling.firstChild.firstChild,this.doesNotAddBorder=f.offsetTop!==5,this.doesAddBorderForTableAndCells=h.offsetTop===5,f.style.position="fixed",f.style.top="20px",this.supportsFixedPosition=f.offsetTop===20||f.offsetTop===15,f.style.position=f.style.top="",e.style.overflow="hidden",e.style.position="relative",this.subtractsBorderForOverflowNotVisible=f.offsetTop===-5,this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==i,a.removeChild(b),a=b=e=f=g=h=null,d.offset.initialize=d.noop},bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;d.offset.initialize(),d.offset.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(d.css(a,"marginTop"))||0,c+=parseFloat(d.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var e=d.css(a,"position");e==="static"&&(a.style.position="relative");var f=d(a),g=f.offset(),h=d.css(a,"top"),i=d.css(a,"left"),j=e==="absolute"&&d.inArray("auto",[h,i])>-1,k={},l={},m,n;j&&(l=f.position()),m=j?l.top:parseInt(h,10)||0,n=j?l.left:parseInt(i,10)||0,d.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):f.css(k)}},d.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),e=cf.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(d.css(a,"marginTop"))||0,c.left-=parseFloat(d.css(a,"marginLeft"))||0,e.top+=parseFloat(d.css(b[0],"borderTopWidth"))||0,e.left+=parseFloat(d.css(b[0],"borderLeftWidth"))||0;return{top:c.top-e.top,left:c.left-e.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&(!cf.test(a.nodeName)&&d.css(a,"position")==="static"))a=a.offsetParent;return a})}}),d.each(["Left","Top"],function(a,c){var e="scroll"+c;d.fn[e]=function(c){var f=this[0],g;if(!f)return null;if(c!==b)return this.each(function(){g=cg(this),g?g.scrollTo(a?d(g).scrollLeft():c,a?c:d(g).scrollTop()):this[e]=c});g=cg(f);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:d.support.boxModel&&g.document.documentElement[e]||g.document.body[e]:f[e]}}),d.each(["Height","Width"],function(a,c){var e=c.toLowerCase();d.fn["inner"+c]=function(){return this[0]?parseFloat(d.css(this[0],e,"padding")):null},d.fn["outer"+c]=function(a){return this[0]?parseFloat(d.css(this[0],e,a?"margin":"border")):null},d.fn[e]=function(a){var f=this[0];if(!f)return a==null?null:this;if(d.isFunction(a))return this.each(function(b){var c=d(this);c[e](a.call(this,b,c[e]()))});if(d.isWindow(f)){var g=f.document.documentElement["client"+c];return f.document.compatMode==="CSS1Compat"&&g||f.document.body["client"+c]||g}if(f.nodeType===9)return Math.max(f.documentElement["client"+c],f.body["scroll"+c],f.documentElement["scroll"+c],f.body["offset"+c],f.documentElement["offset"+c]);if(a===b){var h=d.css(f,e),i=parseFloat(h);return d.isNaN(i)?h:i}return this.css(e,typeof a==="string"?a:a+"px")}}),a.jQuery=a.$=d})(window) 

我的代碼沒有錯誤...

+0

您能否提供一個URL來檢查錯誤? – 2011-03-14 19:29:22

+0

閱讀所有代碼是不可能的...只要把錯誤中涉及到的線條... – Pizzicato 2011-03-14 19:29:42

+8

使用非縮小版本,您將會有更多更容易的時間來找出錯誤。 – Pointy 2011-03-14 19:29:57

回答

2

我建議您調試代碼,最小版本的jQuery的工作只是精細。您的代碼存在問題,這會間接導致Internet Explorer中的錯誤,因此您必須採取措施。

我最喜歡的事情(我就是這樣做的,我只是想出了類似的問題)是

  1. 切出所有的JavaScript和運行它,以確保它的工作原理
  2. 粘貼回在中,在一個時間塊,每次
  3. 測試一旦你找到的JavaScript代碼的違規塊,切說出來,把一切回來,以確保這是唯一的問題
  4. 縮小它在該塊看看哪裏的Internet Explorer被延遲。如果你正在使用PHP,你可能需要做這樣的事情有Internet Explorer跳過導致代碼它失敗

$(「禮[標題]」)。qtip({

 style: { 
     name: 'dark', 
     background: $('.ui-widget-header:first').css('background-color') 
<?php 
//internet explorer is retarded 
if(!preg_match('/MSIE/i',$_SERVER["HTTP_USER_AGENT"])) 
{ 
     echo ", tip: true"; 
} 
?> 
    }, 
    position: { 
     target: 'mouse', 
     corner: { 
      target: 'topLeft', 
      tooltip: 'bottomLeft' 
     } 
    } 

}); 

我希望幫助!(如果有,請標記爲答案)

0

對我來說,設置填充或利潤率爲負數時,這已經在很多地方的在線討論,這出現重新:「IE負填充」。以下是我的IE控制檯的手錶值,證明了這一點。

  • a.prop >> 'paddingTop'
  • a.prop === 「寬度」 || a.prop === 「高度」 >>假
  • Math.max(0,一.now)>> 0
  • a.now >> -1.8277004484618357
  • (a.prop ===「width」|| a.prop ===「height」?Math.max(0,a.now ):a.now)+ a.unit >>「-1.8277004484618357px」
    • a.elem.style [a.prop] =(a.prop ===「width」|| a.prop === 「高度」?Math.max(0,a.now):a.now)+ a.unit >>無效參數

試驗: - a.elem.style [a.prop] = '1像素' >> '1px的' - a.elem.style [a.prop] = '-1px' >>無效的參數

在螺紋過來:StackOverflow: jQuery, IE & Animate提出如下建議:

a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now||0):a.now)+a.unit; 

...這什麼也沒做對我來說。

我真的不認爲這是一個jQuery的bug,我沒有在他們的錯誤跟蹤系統中發現它(我承認我沒有看起來太難),而是一個IE不存在的問題能夠處理負填充/邊距。這是一個艱難的電話,不管jQuery是否應該處理這個問題...

編輯:這被打開爲jQuery bug 4571,他們認爲這種行爲是正確的,開發人員應該更仔細設置邊距/填充值保證金/墊確實無效。他們繼續說,他們希望FF會拋出像IE這樣的錯誤。哇!不要經常聽到!

1

我在一個大的DIV元素上使用了jQuery版本「jquery-1.6.4.min.js」中的「slideToggle」。 「DIV」元素有更多的html元素。 當我嘗試在這個大DIV上加載slideToggle函數時,在Internet Explorer 8(也許在FF上)我收到一個錯誤。不知道什麼是錯誤的真正原因,但我的調查過程中,我發現一個bug到jQuery的:

_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit:a.elem[a.prop]=a.now}}}) 

有一些情況時,「一個」變量「NAN」。正因爲如此,我得到了一些錯誤。 所以我把這個檢查程序內:

if(isNaN(a.now)){return;} 

匆匆我所有的問題。

_default:function(a){if(isNaN(a.now)){return;}a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit:a.elem[a.prop]=a.now}}}) 
+0

確實,這是一個錯誤,但如果你不想修改jQuery源代碼,那麼你可以明確地設置div的邊距。這對我有效。 – bygrace 2013-03-01 13:14:05