`
ljl_xyf
  • 浏览: 619073 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

jQuery自定义类封装

阅读更多

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: "http://www.plusweb.cn" });

a.testFun();

b.testFun();

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics