jquery ui datepicker后退按钮跃升至1899年

时间:2010-09-30 13:25:20

标签: jquery jquery-ui jquery-ui-datepicker

我必须错过某些设置或其他内容,但当我使用后退按钮时,datepicker会从当前年份跳至1899.

还有其他人看过这个并修好过吗?

(你可以看到我注释掉的不同组合。)

    $('.dialog-search,#from')
   .datepicker({
    defaultDate: 'c-1m',
    dateFormat: 'yymmdd',
    //changeMonth: true,
    changeYear: true,
    showAnim: 'fadeIn',
    duration: 200,
    //gotoCurrent: true, 
    showOtherMonths: true,
    selectOtherMonths: true,
    currentText: 'Now',
    shortYearCutoff: '+20',
    //showWeek: true,
    //firstDay: 1,
    numberOfMonths: 1,
    showButtonPanel: true,
    yearRange: 'c-200:c',
    onSelect: function(selectedDate,inst) {
     $('.dialog-search,#from').val(selectedDate);
    }
   });

8 个答案:

答案 0 :(得分:10)

当我有多个具有相同ID的文本输入时,我遇到了这个问题,当你在同一个模型类的页面上有多个编辑器时,很容易使用MVC框架。我通过显式指定Id并将Name保持原样来解决它,因此模型解析适用于回发。

答案 1 :(得分:5)

这是因为在我当前的项目中有多个具有相同ID的输入字段。

我在前端生成了多个表单,在我的框架中使用相同的创建方法。

为了避免在表单创建级别编写显式更改,我执行了以下操作:



//An initialisation method for datepickers
var init_datepickers = function() {
  /* Datepickers */
  $('.datepicker').datepicker({
    dateFormat: "dd/mm/yy" //(I'm in NZ)
  });
}
//Define counter ("datepicker index" aka dpi)
var dpi = 0;
//Loop datepickers
$.each($('input.datepicker'), function() {
  if(dpi > 0)
    $(this).attr("id", $(this).attr("id") + "_" + dpi); //Append the current count to the ID
  dpi++;
  //Check for last datepicker, and call init
  if(dpi == $('input.datepicker').length)
    init_datepickers();
});




这会向所有日期选择器发布一个号码,而不是页面上显示的第一个。

注意:此示例并未真正要求使用ID作为脚本或样式的选择器。这将改变输入的ID,因此,将破坏您可能拥有的任何样式/选择。

答案 2 :(得分:1)

调用

时遇到此问题
$(...).datepicker('destroy')

在重新初始化datepicker之前。

答案 3 :(得分:1)

如果您有一个默认实例,就会发生这种情况,因为在jQuery插件中,它配置的默认日期是1899.

我们必须在此默认日期代码触发时找出原因

答案 4 :(得分:0)

我在jsfiddle中创建了一个包含代码的演示,但我无法重现您的问题。你可以在http://jsfiddle.net/w78xX/查看。

答案 5 :(得分:0)

我有同样的问题。 我正在使用ajax填充datepicker字段,并将它们作为弹出窗口显示在PrettyPhoto上。

这是我的代码。

$( "body" ).on( "focus", ".tarih", function() {
    //$('.tarih').datepicker('destroy');
    var i = 0;
    $('.tarih').each(function () {
        //$(this).attr("id",'date' + i).datepicker('destroy');
        $(this).attr("id",'date' + i).datepicker({
            dateFormat: "yy-mm-dd",
            firstDay: 1,
            minDate: new Date(2000, 1 - 1, 1)
        });
        i++;
    });
});

答案 6 :(得分:0)

尝试使用: 格式:'mm / dd / yyyy hh:ii:ss P' 诀窍是保持日期格式与后端返回的格式相同。

答案 7 :(得分:0)

我遇到了同样的问题,并添加useCurrent: false解决了它。

.datepicker({
        useCurrent: false 

    });
相关问题