jQuery 语法错误,无法识别的表达式:不支持的伪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24238302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax error, unrecognized expression: unsupported pseudo
提问by user500468
Im trying to execute the following code below, but it throws the following error message:
我试图执行下面的代码,但它抛出以下错误消息:
Error: Syntax error, unrecognized expression: unsupported pseudo: really-good-at
错误:语法错误,无法识别的表达式:不受支持的伪:非常擅长
The code:
编码:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
/* Implement a Cesar crypto decrypt for the code.
* [Code ASCII] + n => Decrypted ASCII.
* where n = char pos in cryptedCode string (R=1) */
if ($('.js.php.mysql.html.oop').is(':really-good-at')) {
var cryptedCode = 'RFLLDN';
var decryptedCode = '';
console.log('Enter this code in the form: ' + decryptedCode);
//Open website url
var url = 'aHR0cDovL2JpdC5seS8xN21NRzk4';
window.open(window.atob(url));
}
</script>
<input type="text" class="js.php.mysql.html.oop">
Anyone who can explain why this error is thrown?
谁能解释为什么会抛出这个错误?
回答by doctororange
You can see jQuery's list of valid selectors here: http://api.jquery.com/category/selectors/
您可以在此处查看 jQuery 的有效选择器列表:http: //api.jquery.com/category/selectors/
Your problem is simply that :really-good-at
is not a valid selector.
你的问题只是这:really-good-at
不是一个有效的选择器。
If really-good-at
is a class name, you could use .is('.really-good-at')
如果really-good-at
是类名,则可以使用.is('.really-good-at')
回答by Leo
Well, the error is clear...really-good-at
is NOT a recognized css pseudo selector. You can't just use arbitrary pseudo selectors and expect it work. It's like me trying to speak Spanish in Japan and expecting japanese people to understand what I'm saying
好吧,错误很明显……really-good-at
不是公认的 css 伪选择器。你不能只使用任意的伪选择器并期望它工作。就像我试图在日本说西班牙语并期待日本人理解我在说什么
回答by Fabien Haddadi
A very similar experience just happened to me with a pseudo selector that just didn't make sense. The problem is...it was in my own code!
一个非常相似的经历刚刚发生在我身上,使用了一个没有意义的伪选择器。问题是......它在我自己的代码中!
This is how it was born: - initially it was a valid CSS expression: "td:nth-of-type" used within a callback function, so far so normal. Until I decided to select the whole of that function, and do a massive find/replace on the selected text: replace "type" with "action". Why? Because one of the arguments of that callback was wrongly named "type" instead of "action". This is how my pseudo selector ended up as "nth-of-action", hence triggering a JS error, which in turn stopped processing the rest of the code. As much as I know by experience that massive replaces are dangerous, I still reviewed my code to look for instances of "action", but I didn't see that the pseudo selector nth-of-type has been changed...
它是这样诞生的: - 最初它是一个有效的 CSS 表达式:“td:nth-of-type”在回调函数中使用,到目前为止很正常。直到我决定选择整个函数,并对所选文本进行大量查找/替换:将“类型”替换为“动作”。为什么?因为该回调的参数之一被错误地命名为“type”而不是“action”。这就是我的伪选择器最终成为“nth-of-action”的方式,因此触发了 JS 错误,进而停止处理其余代码。据我所知,大量替换是危险的,我仍然检查了我的代码以寻找“动作”的实例,但我没有看到伪选择器 nth-of-type 已经改变......