如何使用jqueryselect包含特定文本值的跨度?
如何find包含文本“查找我”的范围
<div> <span>FIND ME</span> <span>dont find me</span> </div> http://api.jquery.com/contains-selector/
 $("span:contains('FIND ME')") 
ETA:
包含select器是很好,但过滤跨度列表,如果可能更快: http : //jsperf.com/jquery-contains-vs-filter
 $("span").filter(function() { return ($(this).text().indexOf('FIND ME') > -1) }); -- anywhere match $("span").filter(function() { return ($(this).text() === 'FIND ME') }); -- exact match 
使用包含 :
 $("span:contains('FIND ME')") 
我认为这将工作
 var span; $('span').each(function(){ if($(this).html() == 'FIND ME'){ span = $(this); } }); 
顺便说一句,如果你想用这个variables,你可以这样做:
 function findText() { $('span').css('border', 'none'); //reset all of the spans to no border var find = $('#txtFind').val(); //where txtFind is a simple text input for your search value if (find != null && find.length > 0) { //search every span for this content $("span:contains(" + find + ")").each(function () { $(this).css('border', 'solid 2px red'); //mark the content }); } }