Sim*_*zzi 4 safari syntax-error jquery-deferred safari-web-inspector jquery-3
我对于这个控制台错误有点头疼,仅在Safari上才可以(实际上是在MacBook上工作)。
我有这个功能:
function exists(element){
var exists = document.querySelector(element);
return exists;
}
Run Code Online (Sandbox Code Playgroud)
在另一个函数内部调用:
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");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,在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.
Run Code Online (Sandbox Code Playgroud)
有人知道发生了什么事吗???
在此先感谢大家!
小智 5
缺少右括号,因此您使用的是无效的选择器。(正如Roamer-1888提到的那样)
在以下讨论中测试了不同浏览器中的无效选择器的讨论中,只有Safari才带来严格的错误提示:https : //www.reddit.com/r/firefox/comments/5nbmqi/on_handling_invalid_selector_strings/
对于所有jquery用户:请检查您的jquery版本,因为选择器问题已修正。
我仅在Safari上有此错误
var div = $('<div class="abc">');
Run Code Online (Sandbox Code Playgroud)
声明在Firefox和Chrome上正常运行,但在使用jquery 1.11.1版本时在Safari上无效;但是使用jquery 1.12.4在所有这些程序中都能正常工作。
就我而言,我使用以下语法解决了该问题:
var div = $('<div>', {"class":"abc"});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7057 次 |
| 最近记录: |