|
復(fù)制代碼 代碼如下:
<script>
function HighLight(nWord){
if(nWord!=''){
var keyword = document.body.createTextRange();
while(keyword.findText(nWord)){
keyword.pasteHTML("<span style='color:red;'>" + keyword.text + "</span>");
keyword.moveStart('character',1);
}
}
}
function highword(nWord){
var array = nWord.split(",");
for(var i=0;i<array.length;i++){
HighLight(array[i]);
}
}
</script>
<body onload="highword('li,jin')">
<p>liujinzhong liujinzhong liuzhong</p>
</body>
js高亮方法二:
2.
復(fù)制代碼 代碼如下:
<html>
<head>
<title>Test Page</title>
<script type="text/Javascript">
<!--
function highLight(ele,keys)
{
var reg = new RegExp("(" + keys.replace(/,/,"|") + ")","g");
ele.innerHTML = ele.innerHTML.replace(reg,"<font color=/"red/">$1</font>");
}
window.onload = function()
{
highLight(document.getElementsByTagName("p")[0],"li,jin");
}
//-->
</script>
</head>
<body>
<p>liujinzhong liujinzhong liuzhong</p>
</body>
</html>
JavaScript技術(shù):javascript高亮效果的二種實(shí)現(xiàn)方法,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。