起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2255|回复: 1

[分享] 日历控件 只显示年或者只显示年月

[复制链接]

2

主题

8

帖子

22

积分

新手上路

Rank: 1

积分
22
QQ
发表于 2018-1-2 09:48:35 | 显示全部楼层 |阅读模式
最近在用日历控件的时候,发现没办法只选择年或者只选择年月,在论坛里找了半天也没有找到解决方法,只好自己修改日历控件了,最后完美解决。
修改方法如下:
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方法需要返回一个日期,所以当只选择年的时候,返回的是年+当前月日
发表于 2018-1-2 14:15:10 | 显示全部楼层
类似
http://doc.wex5.com/wex5-ui-question-list-2001/

自己的功能页里面重写样式就可以
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-14 10:20 , Processed in 0.110408 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表