给文本加上<font>标签的问题
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> 色测试 </title>
<script language= "javascript " type= "text/javascript ">
function SetKeyColor(key, color, idStr)
{
if(color == null ||color == " ")
{
color = "red ";
}
SetNode(document.body, key, color, idStr)
}
function SetNode(obj, key, color, idStr)
{
if(obj.hasChildNodes() && obj.nodeType!=3)
{
var childNodes = obj.childNodes;
for(var i=0; i <childNodes.length; i++)
{
SetNode(childNodes[i], key, color, idStr);
}
}
else
{
if(obj.nodeName == "#text " && obj.nodeValue.replace(/^\s*|\s*$/g, " ") != " ")
{
var pid = obj.parentNode.id;
if(pid.indexOf(idStr) > -1)
{
obj.nodeValue = obj.nodeValue.replace(new RegExp(key, "g "), " <font color=red> " + key + " </font> ")
//alert(pid + "\r\n " + obj.nodeValue);