Sto cercando di creare una semplice ricerca di parole jQuery basata su un input di testo tipo e l'evidenziazione del testo. Come posso fare questo per più parole? Questo codice funziona solo per un singolo carattere.Evidenziazione testo suggerimento ricerca semplice Jquery
Html
<input type="text"/>
<div>John Resig
George Martin
Malcom John Sinclair
J. Ohn
Sample text
</div>
CSS
span {
background : red
}
JS
$("input").keyup(function() {
var mysearchword = $("input:text").val();
var word = mysearchword;
$("div:contains('"+word+"')").html(function(i,html) {
var re = new RegExp(word,"g");
return html.replace(re,'<span>'+word+'</span>')
});
});
Questa risposta ti è di aiuto? Http: //stackoverflow.com/questions/8644428/how-to-highlight-text-using-javascript – Tony
Questo tutorial ti sembra utile: http: //www.the -art-of-web.com/javascript/search-highlight/ – Tony
Prova a leggere questo: http://stackoverflow.com/questions/7571117/jquery-something-like-contains-but-to-match-exactly-phrase – Teo