web 开发之js---js 实现文本高亮

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>文字高亮</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="javascript">
function init() {

var keys = new Array("aa", "bb", "cc");

var keysOther = new Array("11", "22", "33");

var reblog = eval("/("+keys.join('|')+")/gi");

document.getElementById("title").innerHTML = document.getElementById("title").innerHTML.replace(reblog,"<font color=red>$1</font>");
document.getElementById("summary").innerHTML = document.getElementById("summary").innerHTML.replace(reblog,"<font color=red>$1</font>");

var reblogOther = eval("/("+keysOther.join('|')+")/gi");

document.getElementById("title").innerHTML = document.getElementById("title").innerHTML.replace(reblogOther,"<font color=yellow>$1</font>");
document.getElementById("summary").innerHTML = document.getElementById("summary").innerHTML.replace(reblogOther,"<font color=yellow>$1</font>");
}



</script>

</head>

<body>
<button onclick="init()">xxxxxxx</button>
<table width="100%" height="100%">
<tr>
<td id="title">
asdasdflsajdfaafdsfjbbfdsffecc11sdfsssscc22222sdfs333
</td>
</tr>
<tr>
<td id="summary">
asdasdflsajdfaafdsfjbbfdsffecc11sdfsssscc22222sdfs333
</td>
</tr>
</table>
</body>
</html>

http://blog.csdn.net/whumr1/article/details/6760746

原文地址:https://www.cnblogs.com/pengkunfan/p/4040374.html