diff --git a/app/static/js/highlight.js b/app/static/js/highlight.js index 2e0d84a..d91fb24 100644 --- a/app/static/js/highlight.js +++ b/app/static/js/highlight.js @@ -29,9 +29,10 @@ function highLight() { if (sel_word1 != null) { var list = sel_word1.value.split(" "); for (var i = 0; i < list.length; ++i) { - list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); + list[i] = list[i].replace(/(^\s*)|(\s*$)/g, "");//消除字符串两边空字符 if (list[i] != "" && "".indexOf(list[i]) == -1 && "".indexOf(list[i]) == -1) { - txt = txt.replace(new RegExp(list[i], "g"), "" + list[i] + ""); + + txt = txt.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " " + list[i] + " "); } } } @@ -40,7 +41,7 @@ function highLight() { for (var i = 0; i < list2.length; ++i) { list2[i] = list2[i].replace(/(^\s*)|(\s*$)/g, ""); if (list2[i] != "" && "".indexOf(list2[i]) == -1 && "".indexOf(list2[i]) == -1) { - txt = txt.replace(new RegExp(list2[i], "g"), "" + list2[i] + ""); + txt = txt.replace(new RegExp("\\s"+list2[i]+"\\s", "g"), " " + list2[i] + " "); } } }