【问题标题】:jQuery Datepicker changes date to todayjQuery Datepicker 将日期更改为今天
【发布时间】:2010-03-25 16:06:19
【问题描述】:

我正在使用 jQuery Datepicker,但在编辑记录时遇到了问题。

// js code
$(function(){
    $(".datepicker").datepicker().datepicker('option', 'dateFormat', 'yy-mm-dd').datepicker('option', 'changeMonth', 'true').datepicker('option', 'changeYear', 'true');
})

// the input
<input type="text" name="valid_from" value="2010-02-27" class="datepicker" />

但是当页面呈现时,显示的日期(并在我打开日期选择器时选择)是今天。

我真的不明白发生了什么。

【问题讨论】:

    标签: javascript jquery jquery-ui datepicker


    【解决方案1】:

    您还应该更改代码以将所有选项放在一个调用中,像这样

      $(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true,changeYear:true});
    

    【讨论】:

      【解决方案2】:

      删除选项:

      .datepicker( "option", "gotoCurrent", true );
      

      这会将您的日期移动到当前日期:gotoCurrent

      【讨论】:

      • 其实我在原始代码上没有那块,我把它放在那里测试,然后将它复制到问题中。所以删除它并不能解决任何问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 2011-06-22
      • 2012-04-14
      相关资源
      最近更新 更多