防止jQuery UI Datepicker(内联类型)选择今天的日期

时间:2018-05-15 11:47:14

标签: javascript jquery jquery-ui jquery-ui-datepicker

jQuery UI Datepicker自动选择今天的日期并将其设置为关联输入元素的值。有没有办法防止这种情况,除了清除beforeShow上的输入字段,如:

beforeShow: function(input, inst) {
    $('#calendar').val(''); 
}

......这既脏又容易出错。

文档似乎没有列出任何方法。有gotoCurrent,但它只会将链接移动到当前选定的日期而不是今天。我想要的是将今天的日期取消选中并将相关的输入字段留空。

但是,我并不是说隐藏今天的日期CSS类,已经涵盖了here

请注意,这只是内联datepicker(绑定到divspan元素)的问题。 tooltip datepicker(绑定到input元素)不会发生这种情况。

2 个答案:

答案 0 :(得分:1)

如果您想要的是阻止今天的突出显示覆盖具有与默认类相同属性的highlight



$("#datepicker").datepicker();

.ui-state-highlight,
.ui-widget-content .ui-state-highlight,
.ui-widget-header .ui-state-highlight {
  border: 1px solid #c5c5c5;
  background: #f6f6f6;
  font-weight: normal;
  color: #454545;
}

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<style>
.ui-state-highlight,
.ui-widget-content .ui-state-highlight,
.ui-widget-header .ui-state-highlight {
  border: 1px solid #c5c5c5;
  background: #f6f6f6;
  font-weight: normal;
  color: #454545;
}
</style>

<p>Date:
  <input type="text" id="datepicker">
</p>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

你可以这样做:

$('.datepicker').datepicker({
  beforeShowDay: function(date) {
    var _date = jQuery.datepicker.formatDate('yy-mm-dd', date);
    return [new Date().toJSON().slice(0,10) != _date]
  }
});

Online Demo (fiddlejs)

相关问题