【发布时间】:2014-06-10 02:35:48
【问题描述】:
我是 Visual Studio Express 2012 for Windows 8 的新手。
我已经能够让一个简单的应用程序正常工作,但它会抛出相同的“异常”。
所以为了测试,我刚开始一个全新的空白JavaScript项目,只是在default.html中链接了jQuery代码,然后运行调试器,仍然抛出以下异常:
Exception was thrown at line 1217, column 4 in ms-appx://xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/Scripts/jquery-2.1.1.js
0x800a139e - JavaScript runtime error: SyntaxError
Exception was thrown at line 1235, column 4 in ms-appx://xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/Scripts/jquery-2.1.1.js
0x800a139e - JavaScript runtime error: SyntaxError
我如何编辑 jQuery 代码或者我需要做些什么来摆脱这个异常被抛出?
第一个异常被抛出的 jQuery 代码部分:
assert(function (div) {
// Support: Windows 8 Native Apps
// The type and name attributes are restricted during .innerHTML assignment
var input = doc.createElement("input");
input.setAttribute("type", "hidden");
div.appendChild(input).setAttribute("name", "D");
// Support: IE8
// Enforce case-sensitivity of name attribute
if (div.querySelectorAll("[name=d]").length) {
rbuggyQSA.push("name" + 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"); // *********** THIS IS LINE 1217 ***********
rbuggyQSA.push(",.*:");
});
抛出第二个异常的 jQuery 代码部分:
if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
docElem.webkitMatchesSelector ||
docElem.mozMatchesSelector ||
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" ); // ***** THIS IS LINE 1235 *****
rbuggyMatches.push( "!=", pseudos );
});
}
TooLongDon'tRead - 我尝试过的事情:
据我了解,它应该抛出异常,但是微软不会批准抛出任何错误/异常的应用程序......我很困惑,没有明确的答案(这很容易找到),因为使用 jquery 和 Visual Studio 可能是每个人都有的问题。我什至尝试使用 jquery2.02,人们说它不会抛出这些异常,但它仍然对我有用。我尝试自己编辑 jquery 代码,但这导致了很多其他错误。
我还在 nuget 中尝试了适用于 windows 8 的 jquery(大约 2 年没有更新了)......我想这应该可以解决这些问题,但它实际上给了我更多的运行时错误。
【问题讨论】:
-
由于 cmets 会出现这些异常,我认为它们会在内部被 jQuery 捕获。如果这些异常从未达到顶级,您确定这是 Microsoft 的问题吗?该应用程序在内部使用异常来传播错误,但这并不罕见,并不意味着应用程序崩溃。如果微软不允许这样做,那就太奇怪了。
-
@sth - 我认为你是对的。当 Visual Studio 配置为中断所有 JavaScript 错误时,可能会出现此问题。此错误是预期的,由 jQuery 处理,但 Visual Studio 不知道。似乎如果我忽略错误并继续,一切都很好......
标签: jquery visual-studio-2012 windows-8