【发布时间】:2018-08-27 12:24:01
【问题描述】:
jQuery datepicker 总是有一个默认的(selectet!)日期(.ui-datepicker-current-day)。如果不设置,则使用当前日期。
- 我的应用程序要求用户选择日期
- 应该没有初始选择!
- 我使用内联(始终可见)日期选择器,因为它具有更好的移动体验。
我可以通过以下方式清除连接的输入字段:$("#datepicker").datepicker("setDate", null); 但这不会从日历中删除 .ui-datepicker-current-day。
在加载时手动删除类,在第一个视图中有效。但是当您更改月份并返回时,当前日期将再次突出显示为选中。
有一些旧的错误报告:
- bugs.jqueryui.com:ticket/7786 + 重复:ticket/8009,ticket/8159
- drupal.org:issues/2004216
但我仍然无法找到有用的解决方案!
这是一个sn-p:
$(function() {
$("#datepicker").datepicker({altField: "#date"});
// remove default date
$("#datepicker").datepicker("setDate", null);
// remove current-day class (because default date is still highlighted)
$("#datepicker").find(".ui-datepicker-current-day").removeClass("ui-datepicker-current-day");
});
.ui-datepicker-current-day a {
background-color: red !important;
}
<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>
DATE:<input disabled="disabled" id="date" name="date" type="text">
<div id="datepicker"></div>
【问题讨论】:
标签: jquery-ui datepicker