【问题标题】:jQuery-UI datepicker without current date?没有当前日期的jQuery-UI日期选择器?
【发布时间】:2018-08-27 12:24:01
【问题描述】:

jQuery datepicker 总是有一个默认的(selectet!)日期(.ui-datepicker-current-day)。如果不设置,则使用当前日期。

  • 我的应用程序要求用户选择日期
  • 应该没有初始选择!
  • 我使用内联(始终可见)日期选择器,因为它具有更好的移动体验。

我可以通过以下方式清除连接的输入字段:$("#datepicker").datepicker("setDate", null); 但这不会从日历中删除 .ui-datepicker-current-day。 在加载时手动删除类,在第一个视图中有效。但是当您更改月份并返回时,当前日期将再次突出显示为选中。

有一些旧的错误报告:

但我仍然无法找到有用的解决方案!

这是一个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


    【解决方案1】:

    所以我想我现在按照你的意图得到了它,删除了今天的亮点。 我已经使用 CSS 用正常日期的样式覆盖了高亮类。

    $(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;
    }
    a.ui-state-default.ui-state-highlight {
        border: 1px solid #c5c5c5;
        background: #f6f6f6;
        font-weight: normal;
        color: #454545;
    }
    a.ui-state-default.ui-state-highlight.ui-state-active {
        border: 1px solid #c5c5c5 !important;
        background: #f6f6f6 !important;
        font-weight: normal !important;
        color: #454545 !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>

    【讨论】:

    • 感谢您的努力,但这仍然解决了我的问题。一旦用户选择了一个日期,我将需要重点课程。在您的解决方案中,当您单击“下一个”(月)按钮和之后的“上一个”(月)按钮(在这种情况下用户没有单击任何日期)时,仍然会突出显示日期(今天)。
    • 好的,它现在应该可以工作了,但是很抱歉弄脏了。默认的高亮(通过切换月份触发)有它自己的类,所以我也重写了它并用 !important 强制它。希望对您有所帮助。
    猜你喜欢
    • 2021-11-05
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多