我是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年内没有更新)...我想这是想解决这个问题,但它实际上给了我更多的运行时错误。
答案 0 :(得分:9)
使用IE11时,我遇到了与jQuery类似的问题。事实证明,即使JQuery 2.1.1声称与IE11兼容,我发现在某些情况下它不会并且返回错误。尝试使用最新的JQuery 1.X版本。它具有与2.1.1完全相同的功能,但仍然具有在2.1.1中删除的IE 7,8和9的兼容性检查。
答案 1 :(得分:4)
如果window
对象可用,请定义window.onerror
函数以捕获所有未捕获的异常:
window.onerror = function (message, url, lineNo)
{
console.log('Error: ' + message + '\n' + 'Line Number: ' + lineNo);
return true;
}
console.log(window);
console.log(1=2);
<强>参考强>
答案 2 :(得分:1)
当我将网页从VS10移动到VS12时,我遇到了同样的错误。我认为这个问题与转移有某种关系。我阅读了上述问题和答案并得出结论,我的错误是使用Windows 8.1和IE 11进行测试。我使用FireFox浏览器测试了我的VS12版本软件,错误已经消失。我不知道如何在IE 11中更改jQuery来构建1.x.如果我这样做,我会因为我希望我的软件能够使用最流行的浏览器进行操作。
感谢您的帮助。