查询高亮或列表加亮的js

<html>
<head>
<title> key </title>
<script type="text/javascript">
<!--
window.onload = function(){
 yit(document.body, '动力火车', '#eee');
 yit(document.body, '风动人', 'yellow');
}

/*
 function authored by Hily Jiang
 http://hily.iyi.cn/
 2007-06-24
*/
function yit(n,k,cl){
 var cs = n.childNodes;
 var i = 0, l = cs.length;
 var t, c, pos, rest;
 t = document.createElement('span');
 t.style.backgroundColor = cl;
 t.innerHTML = k;

 for (; i < l; i++){
  c = cs[i];
  if (c.nodeType == 3){
   t = t.cloneNode(true);
   pos = c.nodeValue.indexOf(k);
   if (pos != -1) {
    rest = c.splitText(pos);
    rest.replaceData(0, k.length, '');
    n.insertBefore(t,rest);
   }
  }
  else yit(cs[i],k,cl);
 }
}
//-->
</script>
</head>

<body>
<ul>
<li>1. 黄阅</li>
<li>2. 黄征</li>
<li>3. 后弦</li >
<li>4. 风动人</li>
<li>5. 齐秦</li>
<li>6. 范范</li>
<li>7. 阿牛</li>
<li>8. 动力火车</li>
<li>9. 还是动力火车</li>
</ul></body>
</html>

posted on 2007-07-26 17:25  sin  阅读(257)  评论(0)    收藏  举报

阳江人才网