注意:如果您使用的是dijit/Calendar
下拉默认值,则使用dropDownDefaultValue
@vogomatix 在另一个答案中所说的属性。
以下是如果您使用的dojox/widget/Calendar
是下拉菜单。
默认情况下,弹出窗口设置为文本框的当前值,如果为空,它将使用当前日期。
你可以做
1)将文本框的值设置为您想要的默认值
或者
2)使用方面设置日历打开时的值。
require([
'dojo/dom',
'dojo/aspect',
'dijit/form/DateTextBox',
'dojox/widget/Calendar'
], function(dom, aspect, DateTextBox, Calendar){
var dt = new DateTextBox({ popupClass: Calendar }, dom.byId('dtText'));
aspect.after(dt, 'openDropDown', function() {
// only default if there is no value
if(dt.get('value') == null) {
// Do not set the text box when changing value,
// so temporarily override the onchange function
var oldOnChange = dt.dropDown.onChange;
dt.dropDown.onChange = function(){};
dt.dropDown.set('value', new Date(1980, 7, 4)); // default to August 4th, 1980
dt.dropDown.onChange = oldOnChange;
}
});
});
看看它的实际效果:
http://jsfiddle.net/cswing/kQYhQ/