jquery 类处理

来源:互联网 发布:家境一般出国留学知乎 编辑:程序博客网 时间:2024/06/10 18:26
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();

0 0
原创粉丝点击