像大家都知道一个按钮是一个按钮...点击,上,下,做到这一点,做到这一点。 所以我写了一些默认的按钮行为“class/object”。扩展二传手默认对象
外部默认button.js:
function Button(parent) {
var self = this;
this.enabled = true;
this.visible = true;
...
this.initialized = false;
f_createButton(parent, self);
this.initialized = true;
...
}
Button.prototype = {
get initialized() {
return this._initialized;
},
set initialized(bool){
this._initialized = bool
if(this.initialized === true) {
... do default stuff
}
},
get enabled(){
return this._enabled;
},
set enabled(bool){
this._enabled = bool;
if(document.getElementById(this.id)) { // is button defined?
var mClassName = document.getElementById(this.id).children[0].className;
document.getElementById(this.id).className = (this.enabled === false) ? "button button-Gray_disabled" : "button button-" + this.defaultStyle;
document.getElementById(this.id).children[0].className = (this.enabled === false) ? mClassName + "_disabled" : mClassName.replace("_disabled","");
}
}
}
function f_createButton("", obj) {
.... create DOM element
}
包括在HTML & button.js延长按钮 “类/对象”:
Object.defineProperty(Button.prototype,"buttonStyle", {
get : function() {
return this._buttonStyle;
},
set : function(str) {
this._buttonStyle = str;
if(this.id !== "undefined" && document.getElementById(this.id)) { // is button defined?
document.getElementById(this.id).style.backgroundImage = 'url(Images/'+this.buttonStyle+'/buttons.png)';
}
}
});
这几乎工作,但它杀死初始化原来的按钮。
Object.defineProperty(Button.prototype,"initialized", {
set : function(bool) {
this._initialized = bool;
if(this.initialized === true) {
this.buttonStyle = "NONE";
}
}
});
如何扩展原始二传手?
这个想法是不改变外部button.js ... – 2013-04-04 21:22:47
即时通讯,有点儿新.... PHP是我的语言... – 2013-04-04 21:26:04
简单,我想添加一些扩展功能button.js和赶上初始化事件...也许我错了我的代码吸盘? – 2013-04-04 21:38:00