如何使用Air Datepicker插件设置多个输入的值?

时间:2016-11-08 15:23:16

标签: javascript jquery datepicker

我无法使用Air Datepicker插件手动设置多个输入的日期(值)。它始终只设置“取件日期”字段,但忽略“交货日期”字段。

HTML

<form>
  <div id="pickupDate" class="form-group">
    <div class="row">
      <div class="col-sm-8 col-xs-offset-2">
        <label class="control-label">Requested Pickup Date <span class="normal">(No Weekend Pickup Available)</span></label>
        <input name="datereqPick" type="text" id="datereqPick" class="form-control clearable" value='' tabindex="1">
      </div>
    </div>
  </div>
  <div id="deliveryDate" class="form-group">
    <div class="row">
      <div class="col-sm-8 col-xs-offset-2">
        <label class="control-label">Delivery Date</label>
        <input name="datereqDel" type="text" id="datereqDel" class="form-control clearable" value='' tabindex="2">
      </div>
    </div>
  </div>
</form>

JS

$(function() {
// Initialize Datepicker
var disabledDays = [0, 6],
    datepicker = $('#datereqPick, #datereqDel').datepicker().data('datepicker'),
    $picker = $('#datereqPick, #datereqDel');
$picker.datepicker({
    language: 'en',
    autoClose: true,
    minDate: new Date(),
    onRenderCell: function(date, cellType) {
        if (cellType == 'day') {
            var day = date.getDay(),
                isDisabled = disabledDays.indexOf(day) != -1;
            return {
                disabled: isDisabled
            };
        }
    },
    onSelect: function(formattedDate, date, inst) {
        datepicker.hide();
    }
});

// Set Dates Manually
$picker.data('datepicker').selectDate(new Date('11/30/2016'));

});

小提琴

我创造了一个小提琴来证明这个问题: https://jsfiddle.net/mp55sqdd/1/

提前感谢您的帮助!

0 个答案:

没有答案