【问题标题】:How To Set Own Default Date In Material-Datetime-Picker如何在 Material-Datetime-Picker 中设置自己的默认日期
【发布时间】:2017-05-07 10:16:02
【问题描述】:

我在这里使用 Material-datetime-picker。但我只需要出生日期(出生日期)。因此在初始时间默认日期应该是从 1990 我应该在 ma​​terial-datetime-picker.js

中应用哪些更改

index.php

var picker = new MaterialDatetimePicker({})

  .on('submit', function(d) {
    var dt = d.format("DD/MM/YYYY");
    $("#dob").val(dt);
  });

$('#dob').click(function () {

picker.open();

});

【问题讨论】:

  • 向我们展示您迄今为止为此编写的代码。
  • 代码太长了怎么上传。
  • 只是您调用/初始化日期选择器代码的部分
  • 我的意思是当用户点击选择器时,日期应该从 1990 年开始显示......我想将它用于 DOB
  • 这是我上传的代码Click Me

标签: javascript php jquery jquery-ui


【解决方案1】:

替换 ma​​terial-datetime-picker.js

中的代码
if (!this.value) {
    // TODO hack
    // set/setDate/setTime need refactoring to have single concerns
    // (set: set the value; setDate/setTime rename to renderDate/renderTime
    //  and deal with updating the view only).
    // For now this allows us to set the default time using the same quantize
    // rules as setting the date explicitly. Setting this.value meets setTime|Date's
    // expectation that we have a value, and `0` guarantees that we will detect
    this.value = moment(0);
    this.setDate(this.options.default);
    this.setTime(this.options.default);
  } else {
    this.setDate(this.value);
    this.setTime(this.value);
  }

收件人

if (!this.value) {
    // TODO hack
    // set/setDate/setTime need refactoring to have single concerns
    // (set: set the value; setDate/setTime rename to renderDate/renderTime
    //  and deal with updating the view only).
    // For now this allows us to set the default time using the same quantize
    // rules as setting the date explicitly. Setting this.value meets setTime|Date's
    // expectation that we have a value, and `0` guarantees that we will detect
    this.value = moment(0);
    this.setDate("12/12/1992");
    this.setTime(this.options.default);
  } else {
    this.setDate(this.value);
    this.setTime(this.value);
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-10
    • 2020-01-23
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    相关资源
    最近更新 更多