Jquery throws IE specific error

2019-05-21 19:40发布

问题:

See the fiddle:

http://jsfiddle.net/JWSaZ/

This works fine in Chrome/FF, but in Internet Explorer it gives an error in the Jquery file:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; Media Center PC 6.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)
Timestamp: Wed, 16 Feb 2011 23:59:13 UTC


Message: Unexpected call to method or property access.
Line: 16
Char: 55207
Code: 0
URI: https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js

回答1:

The error you're getting is due to jQuery needing to call the function resolveWith which contains a try - finally without a catch block. Until IE9, this is not supported by IE and causes the error:

Unexpected call to method or property access.

Essentially, it happens when the IE javascript engine tries to enter the finally block. An easy solution would be to link to your own copy of the jQuery source and add an empty catch block to this function.

Alternately, if you do not have to use HTML5 markup, change your <construct> tags with <p> or a div with an id and change your jQuery selector and your issue should disappear since this jQuery function does not appear to be called. See a working update of your example in IE8 here: http://jsfiddle.net/JWSaZ/21/



回答2:

Your error is when you set the jC2_events variable. In firefox you get something like this:

System:Every tick:Set width to Y-100:#A comment:Set angle to Atan(Self.X-Mouse.X):Finish it #This is a comment Sprite:On event:Do this:Do that:Do something else Clock:Ticks and chimes:Do something:Do it again!:Add one

but in IE 8 you get an empty string. So in ff your for loop loops 6 times but it only loops once in IE and fails on the if statement. Hope this helps.