safari - jQuery.Deferred 异常 : The string did not match the expected pattern

标签 safari syntax-error jquery-deferred safari-web-inspector jquery-3

我对这个控制台错误有点头疼,只在 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 用户:检查您的 jquery 版本,因为已经对选择器问题进行了错误修正。

我只在 Safari 上遇到了同样的错误

var div = $('<div class="abc">');

声明在 Firefox 和 Chrome 上运行良好,但在使用 jquery 1.11.1 版时不适用于 Safari;但是使用 jquery 1.12.4 在所有这些中都可以正常工作。

就我而言,我使用以下语法解决了它:
var div = $('<div>', {"class":"abc"});

关于safari - jQuery.Deferred 异常 : The string did not match the expected pattern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41661708/

相关文章:

python - PIL协助Python

jquery - jquery deferred 中的多个 did() ——它是如何工作的?

javascript - 确保内部延迟在外部 "then"之前完成

php - PDO SQL 查询中的无效参数

macos - 禁用 Safari 14.x 的缓存

javascript - 想要在激活 iOS 键盘时调整浏览器视口(viewport)的大小

javascript - 最大宽度为:100% and height:auto in Safari的图片读取高度

python - Python 以什么顺序查找语法错误?

javascript - 如果有多个动画元素,如何知道 jquery 效果何时结束

javascript - macOS Safari 问题(getUserMedia)以 Angular 6 从摄像头获取视频流 - NotReadableError : The I/O read operation failed