2011-03-14 36 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