jQuery highlight all terms

后端 未结 4 1380
南旧
南旧 2021-01-27 15:23

I\'m trying to highlight search terms but it doesn\'t split the words. Two words take as a one string and highlights only the string as is.

In the demo you can see that

4条回答
  •  孤独总比滥情好
    2021-01-27 15:53

    Supposing you get your string with

    var s = $('#myInput').val();
    

    do

    s.split(' ').forEach(function(token){
        $('p,a').highlight(token);
    });
    

    or

    $("body p").highlight(s.split(' '));
    

提交回复
热议问题