|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 | <?php if($this->is('search')): ?>
<script>
function keyLight(id, key, fontColor, bgColor){
  var oDiv = document.getElementById(id),
      oChilds  = oDiv.childNodes,
      fontColor = fontColor || "red",
      bgColor = bgColor || "transparent",
      sKey = "<strong style='color: "+fontColor+"; background-color: "+bgColor+"; font-weight: normal;'>"+key+"</strong>",
      rStr = new RegExp(key, "g");
  for(var i =0; i<oChilds.length-1; i++){
    if(oChilds[i].nodeType == 3 && /\s/.test(oChilds[i].nodeValue)){  //删除空白的节点
      oChilds[i].parentNode.removeChild(oChilds[i]);
    }
     oChilds[i].innerHTML = oChilds[i].innerHTML.replace(rStr,sKey);  //替换key
  }
}
var key1 = keyLight('searchpage','<?php $this->archiveTitle(' » ', '', ''); ?>');
// var key2 = keyLight('searchpage','微信','#fff','#f00'); 
// 高亮区域ID, 关键字,  背景透明
//支持多关键词、默认字体颜色:红
</script>
<?php endif; ?>
 |