按文字选择链接(完全匹配) [英] Select link by text (exact match)
本文介绍了按文字选择链接(完全匹配)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery,我想选择一个完全包含某种文本的链接.例如:
Using jQuery, I want to select a link that contains exactly some kind of text. For example:
<p><a>This One</a></p>
<p><a>"This One?"</a></p>
<p><a>Unlikely</a></p>
我已经尝试过了:
$('a:contains("This One")')
但是它选择了第一个和第二个链接.我只想要第一个链接,该链接恰好包含"This One".我该怎么办?
But it picks the first AND the second link. I just want the first link, which contains exactly "This One". How can I do that?
推荐答案
您可以执行以下操作:
$('a').filter(function(index) { return $(this).text() === "This One"; });
参考: http://api.jquery.com/filter/
这篇关于按文字选择链接(完全匹配)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文