jquery 插件封装模板

时间:2024-07-21 17:04:02
//插件编写模板
;(function ($) {
$.fn.plugIn = function ( opt ) {
var def = {
//这里填写自定义的参数例如:
event : 'click'
}
opt = $.extend( def , opt );
this.each(function(){ var that = $(this); //that 指的是 .box
//测试执行
that.on( opt.event , function(){
alert( opt.event );
}); });
return this;
}
})(jQuery); //调用
$('.box').plugIn({
event : 'mouseover' //可进行篡改
});