【问题标题】:Custom "fengyuanchen/datepicker" output自定义“fengyuanchen/datepicker”输出
【发布时间】:2018-05-28 16:46:07
【问题描述】:

我正在使用 fengyuanchen/datepicker
我正在尝试导出数据(月份名称、日期名称和日期) 看起来像这样:

我找到了这些选项,但是我无法正确填充它们。

$(document).ready(function() {
$('[data-toggle="datepicker"]').datepicker();
});
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<link href="https://fengyuanchen.github.io/datepicker/css/datepicker.css" rel="stylesheet"/>
<script src="https://fengyuanchen.github.io/datepicker/js/datepicker.js"></script>

<div data-toggle="datepicker" class=" docs-date input-date-picker-from">
  <div class="month" id="putMonthName">January</div>
  <div class="date">5</div>
  <div class="day" id="putDayName">Tuesday</div>
</div>

我只是想在响应的 div 中填充日期

【问题讨论】:

    标签: jquery html jquery-plugins datepicker


    【解决方案1】:

    您应该能够通过覆盖 pick 回调来实现这一点。

    $(document).ready(function() {
        $('[data-toggle="datepicker"]').datepicker({
            autoPick: true,
            pick: function(e){
                e.preventDefault();
                var pickedDate = e.date;              
                var month = $(this).datepicker('getMonthName');
                var date = e.date.getDate();
                var day= $(this).datepicker('getDayName');
                $(".month").html(month);
                $(".date").html(date);
                $(".day").html(day);
                $(this).datepicker('hide'); 
            }
        });
      
    
    });
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <link href="https://fengyuanchen.github.io/datepicker/css/datepicker.css" rel="stylesheet"/>
    <script src="https://fengyuanchen.github.io/datepicker/js/datepicker.js"></script>
    
    <div data-toggle="datepicker" class=" docs-date input-date-picker-from">
      <div class="month" id="putMonthName">January</div>
      <div class="date">5</div>
      <div class="day" id="putDayName">Tuesday</div>
    </div>

    【讨论】:

    • 谢谢你,伙计!这正是我想要的! :) 你能帮我最后一点吗?默认情况下,我需要它在初始化时查看今天的日期
    • 我编辑了我的答案。只需要添加 autoPick: true 这应该允许插件在初始化后自动选择初始日期。
    • 我已经尝试过了,它不起作用,尝试从选择器中更改 MONTH 或 DAY,之后它不会正确附加
    【解决方案2】:

    使用 autoPick: false,

    可以正常使用日期和月份

    【讨论】:

      猜你喜欢
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多