这里使用$.fn.extend的方法来制作jquery插件:
(function($,window,document){
var defaults = {
color: "red",
fontSize: "15px",
content: "你好",
};
$.fn.extend({
fun: function(options){
var opts = $.extend(defaults, options);
return this.each(function(){
//激活事件
var obj = $(this);
obj.click(function(){
obj.css({"color":opts.color,"font-size":opts.fontSize})
obj.html(opts.content);
});
});
}
})
})(jQuery,window,document);
调用方法如下:
$(".testBtn").fun({
color: "blue", //字体颜色
fontSize: "20px", //字体大小
content: "hello", //内容
});
效果如下:
自己写的一款弹出层插件,下载地址:https://download.youkuaiyun.com/download/qq_41756580/10884700