jquery插件编写

来源:互联网 发布:游戏编程师工资高吗 编辑:程序博客网 时间:2024/06/03 18:38

1.创建命名空间

 1   //创建通用的命名空间   2     $.binfire = { 3         //测试 4         test: function () { 5             alert('This is a test. This is only a test.'); 6         }, 7         //判断元素类型,1表示true,0表示false 8         checkEmType: function (o, type) { 9             var f = 0;10             if ($(o).is(type)) {11                 f = 1;12             }13             return f;14         }15         //etc16     };17 18     //方法二19     $.extend({20         binfire: {}21     });22 23     $.extend($.binfire, {24         test: function () { }25     });

2.扩展Jquery函数

    //创建jquery的函数    $.extend({        test: function () {            alert("ff");        },        test1: function () {            alert("test1");        }        //etc    });

3.编写插件格式

 1     //创建对象的插件 2     ;(function ($) { 3         $.fn.extend({ 4             //test函数 5             test: function (value) { 6                 value = $.extend({ 7                     temp: 1000, 8                     name:"binfire", 9                     password:""10                 }, value);11 12                 //内部函数13                 function test1() {14                     alert(value.password);15                 }16 17                 test1();18                 return $(this);19             }20             //....21         });22     })(jQuery);

 

0 0
原创粉丝点击