|
最近在用日历控件的时候,发现没办法只选择年或者只选择年月,在论坛里找了半天也没有找到解决方法,只好自己修改日历控件了,最后完美解决。
修改方法如下:
1:修改 UI2/system/components/justep/datePicker/css/datePicker.css文件,在最后面添加
.x-popPicker[type=yearMonth] .x-popPicker-content .x-year,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-month,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-day,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-hour,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-minute,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-second{
width: 50%;
}
.x-popPicker[type=yearMonth] .x-popPicker-content .x-day,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-hour,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-minute,
.x-popPicker[type=yearMonth] .x-popPicker-content .x-second{
display: none;
}
.x-popPicker[type=year] .x-popPicker-content .x-year,
.x-popPicker[type=year] .x-popPicker-content .x-month,
.x-popPicker[type=year] .x-popPicker-content .x-day,
.x-popPicker[type=year] .x-popPicker-content .x-hour,
.x-popPicker[type=year] .x-popPicker-content .x-minute,
.x-popPicker[type=year] .x-popPicker-content .x-second{
width: 100%;
}
.x-popPicker[type=year] .x-popPicker-content .x-month,
.x-popPicker[type=year] .x-popPicker-content .x-day,
.x-popPicker[type=year] .x-popPicker-content .x-hour,
.x-popPicker[type=year] .x-popPicker-content .x-minute,
.x-popPicker[type=year] .x-popPicker-content .x-second{
display: none;
}
备注:type=yearmonth 和type=year就是我们新增加的类型
2.修改 UI2/system/components/justep/datePicker/datePicker.js 文件的getValue方法
if(this._isPickersCreated){
var nowDate=new Date();
var nowMM=justep.Date.toString(nowDate, "MM");
var nowdd=justep.Date.toString(nowDate, "dd");
if(this.type=='date') return justep.Date.fromString(this._getPickerValue('year')+this._getPickerValue('month')+this._getPickerValue('day'),'yyyyMMdd');
else if(this.type=='datetime') return justep.Date.fromString(this._getPickerValue('year')+this._getPickerValue('month')+this._getPickerValue('day')+this._getPickerValue('hour')+this._getPickerValue('minute')+this._getPickerValue('second'),'yyyyMMddhhmmss');
else if(this.type=='time') return justep.Date.fromString(this._getPickerValue('hour')+this._getPickerValue('minute')+this._getPickerValue('second'),'hhmmss');
else if (this.type=='yearMonth') return justep.Date.fromString(this._getPickerValue('year')+this._getPickerValue('month')+nowdd,'yyyyMMdd');
else if (this.type=='year') return justep.Date.fromString(this._getPickerValue('year')+nowMM+nowdd,'yyyyMMdd');
}
备注:因为GetValue方法需要返回一个日期,所以当只选择年的时候,返回的是年+当前月日
|
|