码迷,mamicode.com
首页 > Web开发 > 详细

jQuery自定义类封装:

时间:2016-09-18 15:28:53      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

jQuery自定义类封装:

 

(function ($) {

    $.DragField = function (arg) {

        var name = "你好";     //这个是私有变量,外部无法访问

        this.testFun = function () {     //this.testFun方法,加上了this,就是公有方法了,外部可以访问。

            alert(arg.title + "," + name);

        };

    };

})(jQuery);

 

使用方法:

var a = new $.DragField({ title: "Hi" });

var b = new $.DragField({ title: "Hello" });

a.testFun();

b.testFun();

jQuery自定义类封装:

标签:

原文地址:http://www.cnblogs.com/PLIN/p/5881391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!