您的位置:首页 > Web前端 > JQuery

jquery自定义类和派生类写法一例

2015-09-29 17:00 597 查看
/**
*定义:表单控件的js类函数
* vp:hsg
* create date:2015-09
* http://blog.csdn.net/hsg77 */
//定义抽象类 基类 表单元素
; (function () {
//
$.FormElement = function () {
//var e = $('#' + e_name);
//默认属性值
var m_oid = '';
var m_Name = '';
var m_width = 800;
var m_height = 600;
//属性的获取与设置方法
this.oid = function () {
return m_oid;
};
this.oid_set = function (value) {
m_oid = value;
};
//
this.Name = function () {
return m_Name;
};
this.Name_set = function (value) {
m_Name = value;
};
//
this.width = function () {
return m_width;
};
this.width_set = function (value) {
m_width = value;
};
//
this.height = function () {
return m_height;
};
this.height_set = function (value) {
m_height = value;
};
//添加方法
this.Msg = function (msg) {
alert(msg);
};
return this;
};
})(jQuery);
//定义js表单对象 FormObject:FormElement 从FormElement基类派生
;(function(){
$.FormObject = function () {
var base = new $.FormElement();
//定义属性
//编辑表名
var m_edit_table_oid = '';
this.edit_table_oid = function () {
return m_edit_table_oid;
}
this.edit_table_oid_set = function (value) {
m_edit_table_oid = value;
}
//比例显示
var m_is_scaledisplay = false;
this.is_scaledisplay = function () {
return m_is_scaledisplay;
}
this.is_scaledisplay_set = function (value) {
m_is_scaledisplay = value;
}
//返回函数本身对象与base对象合并体
return $.extend(true,base, this);
};
})(jQuery);

//测试类代码
var fo = new $.FormObject();
fo.oid_set('oid');
alert(fo.oid());
//
alert(fo.height());
fo.height_set(1000);
alert(fo.height());
//
fo.edit_table_oid_set('ddsssggg');
alert(fo.edit_table_oid());
fo.Msg('good');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: