如何使用jquery选择包含精确文本值的范围? [英] How do I select a span containing an exact text value, using jquery?
本文介绍了如何使用jquery选择包含精确文本值的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
根据精确文本内容选择元素
如何使用jquery选择包含精确文本值的范围?
How do I select a span containing an exact text value, using jquery?
<div>
<span>find me</span>
<span>dont find me</span>
<span>xfind mex</span>
<span>_find me_</span>
</div>
推荐答案
$('span')
.filter(function(){ return $(this).text() == 'find me'; })
.css('color','red');
.filter
允许您应用逻辑元素并仅返回与您的测试匹配的元素。
.filter
allows you to apply logic to the elements and return only those that match your test(s) back.
如果您想要更好的集成版本,这是:text()
选择器:
In case you want a better integrated version, here's a :text()
selector:
(function($){
$.expr[':'].text = function(obj, index, meta, stack){
return ($(obj).text() === meta[3])
};
})(jQuery);
$('span:text("find me")').css('color','red');
这篇关于如何使用jquery选择包含精确文本值的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文