zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    PHP学习——数组处理函数(一)
    PHP与MySQL的连接
    c语言:<tchar.h>
    PHP数组(二)
    PHP数组(一)
    PHP基础知识(三)
    Git和GitHub
    PHP基础知识(二)
    js 全选和反选(复选框)
    python 字典之删除
  • 原文地址:https://www.cnblogs.com/binfire/p/2864705.html
Copyright © 2011-2022 走看看