---
title: "jQuery插件开发,测试"
author: "mailx8"
date: "2017-01-18T14:47:45Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2017-01-18T14:47:45Z"
id: 2353751
url: "https://mailx8.iteye.com/blog/2353751"
---

jQuery插件开发

 

1:(function($){

 

})(jQuery)

 

2:定义方法

   a:

    $.test2=function () {

        alert("test2");

    }

 

   页面中引用 $.test2();

   b:

    $.fn.mytest=function(){

alert("mytest");

    }

   页面中引用 $("#abc").mytest();

   c: 覆盖

    $.extend({

add:function(a,b);

    });

   页面中引用 $.add(3,4);

 

   

完整的例子

   (function($){

    $.test=function () {

        alert("test");

    }

    var private3=function () {

        alert("private3");

    }

    $.fn.mytest=function(){

        var privatetest=function () {

            alert("private");

        }

        privatetest();

        $.test();

        private3();

    }

    $.extend({

        add:function(a,b){return a+b;}

    });

   })(jQuery)