<script> |
| /** |
| * 高亮關(guān)鍵字 |
| * @param nodeID 要高亮的HTML節(jié)點ID |
| * @param key 要高亮的關(guān)鍵字 |
| * @param color 關(guān)鍵字的顏色 |
| */ |
| var highLightKeyWord = function(nodeID, key, color) { |
| var NodeID = nodeID || ""; |
| var keyWord = key || ""; |
| var keyColor = color || "red"; |
| var node = jQuery("#"+nodeID);//可使用document.getElementById替換 |
| if (NodeID != "" && keyWord != "") { |
| var pattern = new RegExp(keyWord, "gi"); |
| var html = node.html(); //可使用innerHTML替換 |
| html = html.replace(pattern, "<font color='"+keyColor+"'>" + keyWord + "</font>"); |
| node.html(html);//可使用innerHTML替換 |
| } |
| } |
| </script> |
| <script>highLightKeyWord('mymps_body','550979');</script> |