Highlight a word with jQuery

后端 未结 12 1569
粉色の甜心
粉色の甜心 2020-11-22 01:20

I basically need to highlight a particular word in a block of text. For example, pretend I wanted to highlight the word "dolor" in this text:



        
12条回答
  •  我在风中等你
    2020-11-22 01:40

    function hiliter(word, element) {
        var rgxp = new RegExp(word, 'g');
        var repl = '' + word + '';
        element.innerHTML = element.innerHTML.replace(rgxp, repl);
    }
    hiliter('dolor');
    

提交回复
热议问题