我对 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/