dhtmlXCalendarObject日历使用

2019-02-15  本文已影响0人  河工狗之王二狗

Calendar

初始化

var myCalendar = new dhtmlXCalendarObject(['i1','i2','i3']) // 数组里面是input的ID

var myCalendar = new dhtmlXCalendarObject([{input: "inputId", button: "iconID"}])

var myCalendar = new dhtmlXCalendarObject([
    { button: 'icon1' },
])
// button属性的值是某个控件的id,可以是span、a、button、i等等……

var from = [
    { type: "settings", position: "label-left", labelWidth: 120, inputWidth: 145 },
    { type: "calendar", label: "Start Date",  dateFormat: "%Y-%m-%d %H:%i", enableTime: true, calendarPosition: "right" },
]
var myFrom = new dhtmlXForm('myFrom', from)

myCalendar = new dhtmlXCalendarObject(myToolbar.getInput("cal_1"))

属性函数

间隔模式的组件

class IntervalDinput {
    constructor(parentList, dictObj) {
        this.myCalendar = new dhtmlXCalendarObject([...parentList])
        this.leftId = '#' + dictObj['leftId']
        this.rightId = '#' + dictObj['rightId']
        this.leftTime = dictObj['leftTime']
        this.rightTime = dictObj['rightTime']
        this.inputBindClick()
        return this.myCalendar
    }
    inputList() {
        let leftInput = document.querySelector(this.leftId)
        let rightInput = document.querySelector(this.rightId)
        let result = [leftInput, rightInput]
        return result
    }
    init() {
        let [leftInput, rightInput] = [...this.inputList()]
        leftInput.value = this.leftTime
        rightInput.value = this.rightTime
    }
    leftBindClick() {
        let [leftInput, rightInput] = [...this.inputList()]
        leftInput.addEventListener('click', () => {
            console.log('click left')
            let maxTime = rightInput.value
            if (maxTime === '') {
                maxTime = null
            }
            console.log(maxTime)
            this.myCalendar.setSensitiveRange(null, maxTime)
        })
    }
    rightBindClick() {
        let [leftInput, rightInput] = [...this.inputList()]
        rightInput.addEventListener('click', () => {
            let minTime = leftInput.value
            console.log(minTime)
            if (minTime === '') {
                minTime = null
            }
            console.log(minTime)
            this.myCalendar.setSensitiveRange(minTime, null)
        })
    }
    inputBindClick() {
        this.leftBindClick()
        this.rightBindClick()
    }
}

// 要用的时候直接实例化它即可达到想要的效果
var intervalInput = new IntervalInput(...)

示例代码

var myCalendar = new dhtmlXDoubleCalendar('i1')
myCalendar.setDateFormat('%Y-%m-%d')
myCalendar.setDates("2012-08-07","2012-08-23")
myCalendar.show() // 上面三行代码执行完,并没有绘制到页面上,所以要show一下

范围和禁用

一些别的属性与函数

dhtmlXCalendarObject.prototype.langData["de"] = {
    dateformat: '%d.%m.%Y',
    monthesFNames: ["Januar",……,'Dezember'月份全名,逗号隔开],
    monthesSNames: ["Jan",……,"Dez"],
    daysFNames: ["Sonntag",……,"Samstag" 星期全名],
    daysSNames: ["So",……,"Sa"],
    weekstart: 一周的起点,
    weekname: "星期的简称",
    today: "语言的“今天”",
    clear: "语言的“清除”"
}

事件

上一篇 下一篇

猜你喜欢

热点阅读