【问题标题】:Bulma calendar date input does not show the pre-populated start dateBulma 日历日期输入不显示预填充的开始日期
【发布时间】:2019-10-24 11:59:00
【问题描述】:

我正在尝试在我的项目中实现 Bulma 日历,但我很难设置默认开始日期。

我正在按照文档执行以下操作。

<input type="date" data-start-date="10/24/2019">

日期选择器打开时日期显示正常:

但是,它并没有显示在输入开头:

最低样板文件在这里: Codepen

【问题讨论】:

    标签: javascript bulma


    【解决方案1】:

    试试这样:

    HTML:

    <input type="date" />
    

    JS:

    // Initialize all input of type date
    var calendars = bulmaCalendar.attach('[type="date"]', {startDate: new Date('10/24/2019')});
    
    // Loop on each calendar initialized
    for(var i = 0; i < calendars.length; i++) {
        // Add listener to date:selected event
        calendars[i].on('select', date => {
            console.log(date);
        });
    }
    
    // To access to bulmaCalendar instance of an element
    var element = document.querySelector('#my-element');
    if (element) {
        // bulmaCalendar instance is available as element.bulmaCalendar
        element.bulmaCalendar.on('select', function(datepicker) {
            console.log(datepicker.data.value());
        });
    }
    

    【讨论】:

      【解决方案2】:

      使用“值”属性,例如日期今天 2021 年 2 月 26 日

      <input type="date" value="2021-02-26">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多