js 实现百度搜索中的高亮显示

highlight: function(value, term) {
  return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong style='color:red'>$1</strong>");
 }

posted @ 2012-08-13 17:22  晓风拂月  阅读(697)  评论(1编辑  收藏  举报