代码之家  ›  专栏  ›  技术社区  ›  scopeak

日期选择器冯元臣/日期选择器只将“天”输出到值中

  •  0
  • scopeak  · 技术社区  · 8 年前

    我正在使用 Datepicker 在提交表单之前,从输入字段中选择日期并将其返回到值中。问题是 .getDate 它只在第一天回来。我需要将值输出为 yyyy-mm-dd

    任何帮助都会很好!

    jQuery('[data-toggle="datepicker"]').datepicker({
      format: 'yyyy-mm-dd',
      pick: function(e) {
        var date = e.date.getDate();
        jQuery(this).attr('value', date)
      }
    });
    <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>
    
    <input id="leftBound" data-date-format="yyyy.mm.dd" data-toggle="datepicker" class="leftBound form-control" type="input" name="left_bound" value="" />
    1 回复  |  直到 8 年前
        1
  •  1
  •   gaetanoM    8 年前

    根据 documentation :

    var date = $(this).datepicker('getDate', true);
    

    jQuery('[data-toggle="datepicker"]').datepicker({
        format: 'yyyy-mm-dd',
        pick: function(e) {
            var date = $(this).datepicker('getDate', true);
            jQuery(this).attr('value', date)
        }
    });
    <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>
    
    
    <input id="leftBound" data-date-format="yyyy.mm.dd" data-toggle="datepicker" class="leftBound form-control" type="input" name="left_bound" value="" />