网络技术 > 前端设计
jQuery自定义类封装
分类:前端设计    时间:2014-08-19    浏览:5247次
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();
Copyright © 2014-2020 XfengNet.COM Inc. All Rights Reserved. 苏ICP备08014032号
返回顶部