7

我現在只是在我的ASP.net網頁(實際上是Site.Master文件)中包含了jQuery(1.9.1,但舊的1.8.3表現方式相同)。一切工作正常在IE9/Win7-64下運行,但自從我升級到IE10(仍然Win7-64),現在當我在本地運行網頁,選擇Internet Explorer並從Visual Studio中運行時,我遇到了異常。在IE10/Win7上運行jQuery崩潰

jquery-1.9.1.js文件的第4224行出現異常。

// Opera 10-12/IE8 - ^= $= *= and empty values 
// Should not select anything 
div.innerHTML = "<input type='hidden' i=''/>"; 
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。我在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"); 

任何人有什麼想法?

+0

什麼是例外?您發佈的代碼中哪一行是4224行? – 2013-02-28 20:36:32

+0

我將對話框中的異常複製到我的問題中,參見上文。 – 2013-02-28 21:08:04

+0

根據jQuery團隊的說法,這很好,因爲它是預期的。他們在更高層次上發現異常並自行處理。跛腳,但這是情況 – 2013-07-11 12:24:08

回答

17

jQuery團隊在某些情況下爲邏輯流程使用異常。 看到我爲WinJS應用程序提出的相同問題提出的這個錯誤:http://bugs.jquery.com/ticket/14123

由於異常的處理,他們不認爲這是一個問題。我這樣做,因爲它使調試應用程序的方式更難,沒有「突破拋出」設置。

所以,這就是問題所在。你無能爲力。

+0

感謝您的新評論。可悲的是,調試我的.Net網絡應用程序要困難得多。 – 2013-07-11 23:46:13

+0

你走了,多年後,我遇到了同樣的麻煩,我試過你所說的一切,仍然沒有改變。該怎麼辦?請幫忙! – 2015-11-09 09:45:33

1

除了消息之外,是否有什麼問題?正如評論所說,「這應該會失敗,並有例外。」該異常由assert()方法處理,不應導致程序終止。在Visual Studio中應該有一個選項才能顯示未處理的異常。

更多信息:This page描述如何在Visual Studio中找到「JavaScript第一次機會例外」設置,關閉它應該消除您所看到的內容。請注意,如果您正在調試promise,您可能不希望將其關閉,鏈接中的文章將對其進行進一步討論。但我相信jQuery在這種情況下正確地處理異常,如果您沒有在調試器中運行,您將看不到該消息。

0

當調試器被設置爲在未捕獲錯誤時中斷時,我在Windows 7上的Safari中遇到了同樣的問題。問題似乎是調試器期望捕獲(e)發生在相同的函數中。如果通過語句繼續執行語句捕獲(五)不挑錯誤了非常清楚以後的斷言()函數:

function assert(fn) { 
    var div = document.createElement("div"); 

    try { 
     return fn(div); 
    } catch (e) { 
     return false; 
    } finally { 
     // release memory in IE 
     div = null; 
    } 
} 

折騰,呵呵!?