【发布时间】:2017-05-30 10:11:59
【问题描述】:
我对这个控制台错误有点头疼,只在 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.
有人知道到底发生了什么???
提前谢谢大家!
【问题讨论】:
-
传递给
exists()的字符串有一个开头[但没有],这足以导致错误。
标签: safari syntax-error jquery-deferred safari-web-inspector jquery-3