1、
dateTextBox.onInput = function(e){
return false;};
阻止了用户输入,日期控件也可以弹出来
2、
dijit.form.TextBox.extend(
editable: true,
_setReadOnlyAttr: function(/*Boolean*/ value){
domAttr.set(this.focusNode, 'readOnly', value || !this.editable);
this._set("readOnly", value);
},
_setEditableAttr: function(value){
this._set("editable", !!value);
domAttr.set(this.textbox, "readonly", (this.readOnly || !value));
}
);
declare 是创建一个新类,extend 是直接扩展基类。这样的好处是,其他基于这个类的类,也跟着可以用。比如TextBox.extend 后,那些 Date、Time、ValidationTextBox 就不用改了
3、
define([
"dojo/_base/declare",
"dijit/form/DateTextBox"
], function(declare, DateTextBox){
return declare([DateTextBox], {
startup: function(){
this.inherited(arguments);
this.textbox.readOnly=true;
},
_setReadOnlyAttr: function(value){
this.set("readOnly", value);
}
})
});
4、
require([ 'dojo/_base/lang', 'dijit/form/DateTextBox', 'dojo/ready', 'dojo/parser' ], function(lang, DateTextBox, ready, parser) { lang.extend(DateTextBox, { startup: function(){ this.textbox.readOnly=true; }, _setReadOnlyAttr: function(value){ this.set("readOnly", value); } }); ready(function(){ parser.parse().then(function(){ // }); }); });