function hightLightTheKeyWord(searchParam,$dom){ if(searchParam&&!/^s*$/.test(searchParam)){ searchParam=regTrim(searchParam); var contents=$dom.html(); var pattern=new RegExp('('+searchParam+')(?=[^<>]*<)','gim'); contents=contents.replace(pattern,"<span style='color:blue'>$1</span>"); $dom.html(contents); } } function regTrim(s){ var imp=/[^.\|()*+-$[]?]/g; var imp_c={ "^":"\^", ".":"\.", "\":"\\", "|":"\|", "(":"\(", ")":"\)", "*":"\*", "+":"\+", "-":"\-)", "$":"\$)", "[":"\[)", "]":"\])", "?":"\?" }; s.replace(imp,function(o){ return imp_c[o]; }); return s; }