淘汰datepicker datemanipulation更新第二datepickerfield

时间:2017-09-27 15:46:01

标签: javascript html knockout.js datepicker

我有3个Datepicker字段,我想更新。 例如:我选择今天的日期,在第二个字段中应该显示该月的最后一天,但提前3个月。

我做了宽度javascript ID,但现在我必须用淘汰赛

我有3个测试字段

<div id="someTest">
  <div>expirationDate
    <div class="input-col input-col-riskdetails input-col-date">
      <input data-bind="value: expirationDate, event: {change: expirationDateChanged}" type="datetime">
    </div>
  </div>

  <div>latestNoticeScheduleDate
    <div class="input-col input-col-riskdetails input-col-date">
      <input data-bind="value: latestNoticeScheduleDate" type="datetime">
    </div>
  </div>

  <div>earlyExchangeDate
    <div class="input-col input-col-riskdetails input-col-date">
      <input data-bind="value: earlyExchangeDate" type="datetime">
    </div>
  </div>
</div>

他们都像这样绑定。

self.expirationDate = ko.observable("");
self.latestNoticeScheduleDate = ko.observable("");
self.earlyExchangeDate = ko.observable("");

self.expirationDateChanged = function () {
    //do the callculation and put the result in the fields
}

这是旧函数的逻辑。怎么可能把它转移到淘汰赛?

    $("#expirationDateDefault").change(function() {
  // Edit after 10 digits
  if ($("#expirationDateDefault").val().length === 10) {
    // only add date if other fields are empty
    if ($("#latestNoticeScheduleDateDefault").val() === '') {
      var sk = $("#expirationDateDefault").datepicker('getDate');

      // Definition is: Current selection minus 3 months
      // Attention: Datepicker is zerobased
      sk = new Date(sk.getFullYear(), (sk.getMonth() + 1) - 3, 0);
      // Set new date
      $("#latestNoticeScheduleDateDefault").datepicker('update', sk);

      var fa = $("#expirationDateDefault").datepicker('getDate');
      // Definition is: Current selection plus one day
      fa = new Date(fa.getFullYear(), fa.getMonth(), fa.getDate() + 1);
      // Set new date
      $('#earlyExchangeDateDefault').datepicker('update', fa);
    }
  }
});

Datepicker绑定为以下

// DatePicker Binding
    BindDatePicker($("body"));

// Date-Picker
function BindDatePicker(context) {
    // Datepicker init
    $('input[type=datetime]', $(context)).datepicker({
        format: "dd.mm.yyyy",
        language: "de",
        calendarWeeks: true,
        autoclose: true,
        todayHighlight: true,
        todayBtn: "linked",
        onClose: this,
        orientation: "auto right"
    });

    $('input[type=datetime]', $(context)).attr("autocomplete", "off");
}

0 个答案:

没有答案