jQuery.Deferred异常:字符串与预期的模式不匹配

编程入门 行业动态 更新时间:2024-10-08 22:47:06
本文介绍了jQuery.Deferred异常:字符串与预期的模式不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对于这个控制台错误有点头疼,仅在Safari上才可以(实际上是在MacBook上工作).

I've a little headache with this console error, ONLY on Safari (working on MacBook actually).

我有这个功能:

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上,控制台会抛出此错误:

Now, on Chrome works like a charm, but on Safari the console throw this error:

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.

有人知道发生了什么事吗?

Someone have idea what hell happening???

先谢谢大家!

推荐答案

缺少右括号,因此您使用的是无效的选择器. (正如Roamer-1888在评论中提到的那样)

There is a closing bracket missing, so you are using an invalid selector. (as Roamer-1888 mentioned as comment)

在以下讨论中测试了不同浏览器中的无效选择器的情况下,只有Safari才提出严格的错误提示: www.reddit/r/firefox/comments/5nbmqi/on_handling_invalid_selector_strings/

Having a look at the following discussion where invalid selectors in different browsers has been tested, only Safari is that strict bringing up errors: www.reddit/r/firefox/comments/5nbmqi/on_handling_invalid_selector_strings/

对于所有jquery用户:,因为选择器问题已修正,请检查您的jquery版本.

For all jquery-Users: check your jquery version, as there has been bugfixes on selector issues.

在此声明中,我在Safari上只有 错误

I had the same error only on Safari on this statement

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

使用jquery 1.11.1版本时,该语句在Firefox和Chrome上运行良好,但在Safari上运行不正常;但是使用jquery 1.12.4可以很好地解决所有问题.

A statement working fine on Firefox and Chrome, but not on Safari when using version jquery 1.11.1; but working fine in all of them with jquery 1.12.4.

就我而言,我使用以下语法解决了该问题:

In my case I solved it using the following syntax:

var div = $('<div>', {"class":"abc"});

更多推荐

jQuery.Deferred异常:字符串与预期的模式不匹配

本文发布于:2023-11-25 10:16:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   不匹配   异常   模式   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!