Jquery实现
(function($) { $.fn.GL = function(options) { var dataop = { ocolor: 'red', oshuru: '����', }; var chuancan = $.extend(dataop, options); $(this).each(function() { var _this = $(this); _this.find($(".glnow")).each(function() { $(this).css({ color: "" }); }); }); if (chuancan.oshuru == '') { return false; } else { $(this).each(function() { var _this1 = $(this); var html = _this1.html(); var newHtml = html.replace(chuancan.oshuru, '<span class="glnow" style="color:' + chuancan.ocolor + '">' + chuancan.oshuru +'</span>'); _this1.html(newHtml); }); } } })(jQuery); /*再到调用页面初始化*/ $('.high-light').GL({ ocolor: '#f4aa2f', oshuru: this.search });