function keywordHighlight(idHtmlContent,keyword) {
var content= $("#"+idHtmlContent).html();//获取内容if ($.trim(keyword)==""){ return;//关键字为空则返回}var htmlReg = new RegExp("\<.*?\>", "i");var arrA = new Array();//替换HTML标签for (var i = 0; true; i++) { var m = htmlReg.exec(content); if (m) { arrA[i] = m; }else { break; } content = content.replace(m, "{[(" + i + ")]}");}words = unescape(keyword.replace(/\+/g, ' ')).split(/\s+/);//替换关键字 for (w = 0; w < words.length; w++) { var r = new RegExp("(" + words[w].replace(/[(){}.+*?^$|\\\[\]]/g, "\\$&") + ")", "ig"); content = content.replace(r, ""+words[w]+"");//关键字样式}//恢复HTML标签 for (var i = 0; i < arrA.length; i++) { content = content.replace("{[(" + i + ")]}", arrA[i]);} $("#"+idHtmlContent).html(content);
}