// 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);
详细解决方案
文本改换JS插件
热度:346 发布时间:2012-11-07 09:56:10.0
相关解决方案