This is okay $('#-6ren">
gpt4 book ai didi

javascript - jquery ":contains"选择器是否接受这种值 "Banking and Finance"?

转载 作者:行者123 更新时间:2023-11-30 09:09:26 27 4
gpt4 key购买 nike

我对 jquery 中的 contains 有疑问。好像只接受一个词。不是一个短语或两个词。

例子:

$('#div:contains('Word')'); --> This is okay

$('#div:contains('Just another word')'); --> This will return empty/this will not match.

你有遇到过这类问题吗?

非常感谢您的回复。

最佳答案

您需要的是使用双引号(而不是那些包裹整个选择器的单引号),例如:

$("p:contains('John Resig')");

这将选择正确的段落,其中包含字符串 'John Resig'

或者你可以反转它:

$('p:contains("John Resig")');

或者你可以使用旧的好转义:

$('p:contains(\'John Resig\')');

关于javascript - jquery ":contains"选择器是否接受这种值 "Banking and Finance"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1580859/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com