jquery插件编写

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         //etc
16     };
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);

 

posted @ 2013-01-17 16:12  binfire005  阅读(499)  评论(0编辑  收藏  举报