jquery 插件封装模板

在开发中很多时候要用到插件封装,但是很多时候会忘记模板怎么写,这里留个记号,到时候直接拿来用即可。

//插件编写模板
;(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' //可进行篡改
});

 

posted @ 2016-01-21 14:05  Zion0707  阅读(193)  评论(0编辑  收藏  举报