日期:2014-05-16 浏览次数:20368 次
// JavaScript Document
(function($){
?$.fn.searchText = function (opt){?
??var defaults = {
???searchText:'',
???targetText:'',
???replaceTextBefore:'',
???replaceTextEnd:'',
???replaceFlag:false,
???startNum:0,
???endNum:0,
???regExp:'',
???warning:'search over'
??}
??$(this).click(function(){
???var rng = createRange(opt.targetText);
???rng.moveStart("character",opt.startNum);
???rng.moveEnd("character",opt.endNum);
???if(rng.findText(opt.searchText))
????rng.select();
???else{
????alert(opt.warning);
????rng = createRange(opt.targetText);
???}
???if(opt.replaceFlag)
????rng.text = opt.replaceTextBefore+opt.searchText+opt.replaceTextEnd;?
???$(this).unbind('click');
??});
??
??$(this).each(function(){ opt= $.extend(defaults,opt)});
??
??createRange = function(target){
???return document.getElementById(target).createTextRange();
??}
?};?
???
})(jQuery);