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 @ 2018-01-23 11:53  anne_zhou  阅读(361)  评论(0编辑  收藏  举报