문제

Possible Duplicate:
Highlight text range using JavaScript
Find text string in jQuery and make it bold

Supposing I have a bunch of file paths, similar to:

  • /Volumes/A//Array/05_SCRIPTS/staging/tree/04_OUTPUTS/MPEG_FF_PS_wCropping/01_NBC_Youtube/Backlog/Archive/LawAndOrder_S20

  • /Volumes/A//AArray/05_SCRIPTS/staging/tree/04_OUTPUTS/MPEG_FF_PS_wCropping/01_NBC_Youtube/Backlog/Archive/LawAndOrder_S20/nbcnetwork-pds-E8818-US-insert-20121020

How would I highlight all matches of specific text on the page. For example, if "04" was what I was looking for, it would do something like:

$(source).find('04').addClass('highlight');

This is pseudocode that is probably way off the mark, but this is what I'm looking to do.

도움이 되었습니까?

해결책

http://jsfiddle.net/Aku4y/

var t = $(source).html();
t = t.replace(/04/g, "<span class='highlight'>04</span>");
$(source).html(t);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top