1.ソースコード 复制代码代码如下: var $keyword = $("#Text1").val() <BR>setHeightKeyWord(' bbb', $keyword, 'Red', true) <BR>}) <BR>}); <BR>function setHeightKeyWord(id, キーワード, カラー, 太字) { <BR>if (キーワード == "") <BR>return; <BR>var tempHTML = $("#" id).html(); <BR>var htmlReg = new RegExp("<.*?>", "i"); <br>var arrA = 新しい 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>ブレーク; <br>} <br>tempHTML = tempHTML.replace(m, "[[[[" i "]]]]"); <br>} <br>var replaceText <br>if (太字) <br>replaceText = "<b style='color:" color ";'>$1</b>"; <BR>else <BR>replaceText = "<font style='color:" color ";'>$1</font>"; <br>var arrayWord = キーワード.split(','); <br>for (var w = 0; w <arrayword.length w>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>tempHTML = tempHTML.replace("[[[[" i "]]]]", arrA[i ]); <br>} <br>$("#" id).html(tempHTML); <br>} <br>