jQuery写组件适当暴露

来源:互联网 发布:易语言英语考试软件 编辑:程序博客网 时间:2024/06/04 19:27
//适当暴露一些默认设置
(function($){
$.fn.hilight = function(options){
var opts = $.extend({},$.fn.hilight.defaults,options);
var $this = $(this);
$this.css(opts);
}

$.fn.hilight.defaults = {
foreground : 'red',
background : 'blue'
}
})(jQuery),function(e){
e.fn.testHilight = function(options){
var defaults = {
foreground : 'red',
background : 'yellow'}
var opts = $.extend({},defaults,options);
var $this = $(this);
$this.css(opts);
}
}(jQuery),function(f){
f.fn.testAnotherHilight = function(options){
var defaults = {
foreground : 'red',
background : 'gray'}
var opts = $.extend({},defaults,options);
var $this = $(this);
$this.css(opts);
}
}(jQuery),function(a){
//适当暴露写函数
a.fn.hilightFormat = function(){
return this.each(function(){
var $this = $(this);
var thisHtml = $this.html();
var formatHtml = a.fn.hilightFormat.format(thisHtml);
$this.html(formatHtml);
});
}
a.fn.hilightFormat.format = function(txt){
return "<strong>" + txt + "<//strong>";
}
}(jQuery)


$(function(){
$.fn.hilight.defaults = {background : 'black'};
//$("#test").hilight();
$(".hilightFormat > p").hilightFormat();


console.log($(".test").metadata().some);
});

0 0
原创粉丝点击