在IE10 / Win7上运行jQuery崩溃

我现在只是在我的ASP.net网页(实际上是Site.Master文件)中包含jQuery(1.9.1,但旧的1.8.3表现相同)。 在IE9 / Win7-64下运行良好,但自从我升级到IE10(仍然是Win7-64)后,现在当我在本地运行网页,选择Internet Explorer并在Visual Studio中运行时,我遇到了exception。

例外是在jquery-1.9.1.js文件的第4224行。

// Opera 10-12/IE8 - ^= $= *= and empty values // Should not select anything div.innerHTML = ""; if ( div.querySelectorAll("[i^='']").length ) { rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:\"\"|'')" ); } // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled) // IE8 throws error here and will not see later tests if ( !div.querySelectorAll(":enabled").length ) { rbuggyQSA.push( ":enabled", ":disabled" ); } // Opera 10-11 does not throw on post-comma invalid pseudos div.querySelectorAll("*,:x"); rbuggyQSA.push(",.*:"); 

jQuery,无论新旧,似乎都无法在Windows 7上正确处理IE10。 我在Opera 10-11崩溃了,这很有意思。

我也看到了4242的崩溃

 if ( (support.matchesSelector = isNative( (matches = docElem.matchesSelector || docElem.mozMatchesSelector || docElem.webkitMatchesSelector || docElem.oMatchesSelector || docElem.msMatchesSelector) )) ) { assert(function( div ) { // Check to see if it's possible to do matchesSelector // on a disconnected node (IE 9) support.disconnectedMatch = matches.call( div, "div" ); // This should fail with an exception // Gecko does not error, returns false instead matches.call( div, "[s!='']:x" ); rbuggyMatches.push( "!=", pseudos ); }); 

以下是其中一个错误:

 Exception was thrown at line 4224, column 4 in http://localhost:49928/jquery/jquery-1.9.1.js 0x800a139e - JavaScript runtime error: SyntaxError Source line: div.querySelectorAll("*,:x"); 

有人有什么想法吗?

jQuery团队在某些情况下使用exception来处理逻辑流程。 看到我在WinJS应用程序中遇到同样问题的错误: http ://bugs.jquery.com/ticket/14123

自处理exception以来,他们认为不是问题。 我这样做,因为它在没有“break on throw”设置的情况下更难调试应用程序。

那就是问题所在。 你无能为力。

除了消息,出了什么问题? 正如评论所说,“这应该失败,但有例外。” exception由assert()方法处理,不应导致程序终止。 Visual Studio中应该有一个选项,仅显示未处理的exception。

更多信息: 此页面描述了如何在Visual Studio中找到“JavaScript first chance exceptions”设置,将其关闭可以消除您所看到的内容。 请注意,如果您正在调试promise,则可能不希望将其关闭,链接中的文章将进一步讨论它。 但我相信jQuery在这种情况下正确处理exception,如果你没有在调试器中运行,你就不会看到消息。

当调试器设置为在未捕获的错误上中断时,我在Windows 7上的Safari中遇到了同样的问题。 问题似乎是调试器期望catch(e)发生在同一个函数中。 如果继续执行语句语句,catch(e)确实会在以后的assert()函数中很好地选择错误:

 function assert( fn ) { var div = document.createElement("div"); try { return fn( div ); } catch (e) { return false; } finally { // release memory in IE div = null; } } 

令人沮丧,呵呵!?