function SearchHighlight(mytag) {
if (!document.createElement)
{
return;
}
var q = "{{$q}}";//要高亮显示的关键字
var l = document.getElementsByTagName(mytag);
if("" == q) return;
words = unescape(q.replace(/+/g,' ')).split(/s+/);
for (w=0;w<words.length;w++) {
for(i=0;i<l.length;i++)
{
var pa = new RegExp("("+words[w]+")","ig");
if(l.parentNode.parentNode.parentNode.id != "header")//标题中的内容不替换
l.innerHTML = l.innerHTML.replace(pa,"<span class="searchword">$1</span>");
}
}
}
代码效果是怎么弄得阿
回复 更多评论