1.源码 复制代码 代码如下: <BR>$(function() { <BR>$("#btn_1").click(function() { <BR>var $keyword = $("#Text1").val() <BR>setHeightKeyWord('bbb', $keyword, 'Red', true) <BR>}); <BR>}); <BR>function setHeightKeyWord(id, keyword, color, bold) { <BR>if (keyword == "") <BR>return; <BR>var tempHTML = $("#" + id).html(); <BR>var htmlReg = new RegExp("\<.*?\>", "i"); <BR>var arrA = new Array(); <BR>for (var i = 0; true; i++) { <BR>var m = htmlReg.exec(tempHTML); <BR>if (m) { <BR>arrA[i] = m; <BR>} <BR>else { <BR>break; <BR>} <BR>tempHTML = tempHTML.replace(m, "[[[[" + i + "]]]]"); <BR>} <BR>var replaceText <BR>if (bold) <BR>replaceText = "<b style='color:" + color + ";'>$1"; <BR>else <BR>replaceText = "<font style='color:" + color + ";'>$1"; <BR>var arrayWord = keyword.split(','); <BR>for (var w = 0; w < arrayWord.length; w++) { <BR>var r = new RegExp("(" + arrayWord[w].replace(/[(){}.+*?^$|\\\[\]]/g, "\\$&") + ")", "ig"); <BR>tempHTML = tempHTML.replace(r, replaceText); <BR>} <BR>for (var i = 0; i < arrA.length; i++) { <BR>tempHTML = tempHTML.replace("[[[[" + i + "]]]]", arrA[i]); <BR>} <BR>$("#" + id).html(tempHTML); <BR>} <BR>