简体   繁体   English

从jQuery移植到Zepto时,不是有效的选择器错误

[英]Not a valid selector error while porting from jQuery to Zepto

I am trying to use Zepto in jQuery's place for vex.js plugin. 我正在尝试在jQuery的vex.js插件中使用Zepto。

 ".vex:not(".vex-closing") .vex-content"

I am getting below error, while performing above selector. 我在选择器上方执行操作时遇到错误。

 error performing selector: ".vex:not(".vex-closing") .vex-content" zepto.min.js:3
 Uncaught SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '.vex:not(".vex-closing") .vex-content' is not a valid selector. 

How can I fix this issue. 我该如何解决此问题。

Here is the code extracted from vex.js 这是从vex.js中提取的代码

 getAllVexes: function() { 
    return $("." + vex.baseClassNames.vex + ":not(\"." + vex.baseClassNames.closing + "\") ." + vex.baseClassNames.content);
 }

Quotes aren't normally allowed in the :not() selector, since it accepts a selector, not a string. :not()选择器通常不允许使用引号,因为它接受选择器,而不是字符串。 For whatever reason, though, quotes are allowed in jQuery/Sizzle's implementation of :not() . 不管出于什么原因, jQuery / Sizzle的:not()实现中允许使用引号

You should remove the \\" marks from your selector string for it to work in document.querySelectorAll() (which Zepto appears to call directly, and use exclusively for selector matching — correct me if I'm wrong): 您应该从选择器字符串中删除\\"标记,以使其在document.querySelectorAll()起作用(Zepto似乎直接调用它,并且专门用于选择器匹配-如果我错了,请纠正我):

return $("." + vex.baseClassNames.vex + ":not(." + vex.baseClassNames.closing + ") ." + vex.baseClassNames.content);

This will result in a selector like .vex:not(.vex-closing) .vex-content , which is a valid CSS selector. 这将导致选择器如.vex:not(.vex-closing) .vex-content ,这是有效的CSS选择器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM