简体   繁体   English

为什么我不能在单独的字段中重复使用我的 Pikaday 日历?

[英]Why can't I reuse my Pikaday calendar in a separate field?

I'm using Pikaday in my web application and I have 2 input fields where I want to use the same instance of my calendar.我在我的网络应用程序中使用 Pikaday,我有 2 个输入字段,我想在其中使用我的日历的相同实例。

 var picker = new Pikaday({
        field: $('.datePickerPerDay')[0],
        format: 'MM/DD/YYYY',
        minDate: moment().toDate()
    });

This is how I define my calendar.这就是我定义日历的方式。 Then.然后。 I give both input fields the class "datePickerPerDay".我为两个输入字段提供了“datePickerPerDay”类。 But it only works for one of the inputs and not the other.但它只适用于其中一个输入,而不适用于另一个。 Why is this happening?为什么会这样? is it possible to use it like I want?可以像我想要的那样使用它吗?

Just loop over the .datePickerPerDay elements and create a new Pikaday instance for each of them:只需遍历.datePickerPerDay元素并为每个元素创建一个新的 Pikaday 实例:

$('.datePickerPerDay').each(function() {
  var picker = new Pikaday({
    field: this,
    format: 'MM/DD/YYYY',
    minDate: moment().toDate()
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM