Jquery 日期选择器格式问题

标签 jquery date datepicker

当我在输入字段中输入字符串 01/01/24 时,它会返回日期 01/01/2024 但如果我输入 01/01/25 它返回日期 01/01/1925

是否可以阻止此事件并始终返回 2000 之后的日期?

用户不希望我使用 dd/mm/yy 更改 dateFormat,因此我只能使用 dd/mm 格式/y.

这是我用来创建日期选择器的js:

$('.hasDatepicker').datepicker({
    showOn: "button",
    buttonImage: imagePrefix + "/img/calendar_1.png",
    buttonImageOnly: true,
    dateFormat: "dd/mm/y",
    yearRange: "2000:2099",
    onSelect: function(e, d) {
        $(this).trigger("change");
    }
});

最佳答案

这是因为选项shortYearCutoff :

The cutoff year for determining the century for a date (used in conjunction with dateFormat 'y'). Any dates entered with a year value less than or equal to the cutoff year are considered to be in the current century, while those greater than it are deemed to be in the previous century.

默认值为+10,您可以将其放大到+50等大值。

演示:http://jsfiddle.net/IrvinDominin/5Db32/

关于Jquery 日期选择器格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25141034/

相关文章:

MySQL 获取出生日期/生日的下一个实例

ios - 自定义 DatePicker-iOS

javascript - Jquery datepicker 图标位置不正确

javascript - 关注 JqueryUI Datepicker 中 TextField 中的日期

php - 为什么使用 AJAX 调用 php 方法时会得到 undefined index ?

javascript - 防止 $(window).on('scroll function) 在 .click 函数之后触发

用于查找字符串的 jquery 选择器

java - 使用 SimpleDateFormat 在 Java 中格式化 JavaScript jQuery 日期格式

Jquery Draggable 不适用于 chrome 和 opera

Python-将一个时间段分割成多个固定长度的时间段