jQuery highlight all terms

后端 未结 4 1486
南旧
南旧 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:51

    Hopefully you are searching for this:

     var term = $('#q').val();
     $.each(term.split(" "),function(i,v){
         $('p,a').highlight(v);
     });
    

提交回复
热议问题