jQuery.Deferred 异常:字符串与预期模式不匹配
jQuery.Deferred exception: The string did not match the expected pattern
这个控制台错误让我有点头疼,仅在 Safari 上(实际上在 MacBook 上工作)。
我有这个功能:
function exists(element){
var exists = document.querySelector(element);
return exists;
}
在另一个函数中调用:
function includeHoverStylesheet(){
var path = $("body").attr("data-hover");
if (!("ontouchstart" in document.documentElement || exists("link[href='" + path + "'"))) {
var link = document.createElement("link");
link.rel = "stylesheet", link.href = path, document.head.appendChild(link) && document.body.removeAttribute("data-hover");
}
}
现在,在 Chrome 上工作得很好,但在 Safari 上,控制台会抛出此错误:
1) Invalid CSS property declaration at: *
2) jQuery.Deferred exception: The string did not match the expected pattern.
3) SyntaxError (DOM Exception 12): The string did not match the expected pattern.
有人知道到底发生了什么事吗???
提前谢谢大家!
缺少右括号,因此您使用的选择器无效。 (如评论中提到的 Roamer-1888)
看看下面的讨论,其中已经测试了不同浏览器中的无效选择器,只有 Safari 是严格报错的:
https://www.reddit.com/r/firefox/comments/5nbmqi/on_handling_invalid_selector_strings/
对于所有 jquery-Users: 检查您的 jquery 版本,因为已经修复了选择器问题。
我在 Safari 上仅遇到了同样的错误
var div = $('<div class="abc">');
一条声明在 Firefox 和 Chrome 上运行良好,但在使用版本 jquery 1.11.1 时在 Safari 上运行不佳;但在 jquery 1.12.4.
中都可以正常工作
在我的例子中,我使用以下语法解决了它:
var div = $('<div>', {"class":"abc"});
这个控制台错误让我有点头疼,仅在 Safari 上(实际上在 MacBook 上工作)。
我有这个功能:
function exists(element){
var exists = document.querySelector(element);
return exists;
}
在另一个函数中调用:
function includeHoverStylesheet(){
var path = $("body").attr("data-hover");
if (!("ontouchstart" in document.documentElement || exists("link[href='" + path + "'"))) {
var link = document.createElement("link");
link.rel = "stylesheet", link.href = path, document.head.appendChild(link) && document.body.removeAttribute("data-hover");
}
}
现在,在 Chrome 上工作得很好,但在 Safari 上,控制台会抛出此错误:
1) Invalid CSS property declaration at: *
2) jQuery.Deferred exception: The string did not match the expected pattern.
3) SyntaxError (DOM Exception 12): The string did not match the expected pattern.
有人知道到底发生了什么事吗???
提前谢谢大家!
缺少右括号,因此您使用的选择器无效。 (如评论中提到的 Roamer-1888)
看看下面的讨论,其中已经测试了不同浏览器中的无效选择器,只有 Safari 是严格报错的: https://www.reddit.com/r/firefox/comments/5nbmqi/on_handling_invalid_selector_strings/
对于所有 jquery-Users: 检查您的 jquery 版本,因为已经修复了选择器问题。
我在 Safari 上仅遇到了同样的错误
var div = $('<div class="abc">');
一条声明在 Firefox 和 Chrome 上运行良好,但在使用版本 jquery 1.11.1 时在 Safari 上运行不佳;但在 jquery 1.12.4.
中都可以正常工作在我的例子中,我使用以下语法解决了它:
var div = $('<div>', {"class":"abc"});