这是因为 Bootstrap 日期选择器正在使用 JavaScript Date objects。当你创建一个新的 Date 对象并传入一个两位数的年份时,它将输出 1900+年(参见Why does Javascript evaluate a 2-digit year of 00 as 1900 instead of 2000?)
您可以尝试调整日期选择器源代码,但这可能太复杂了。
根据我在http://www.eyecon.ro/bootstrap-datepicker/ 上看到的信息,没有设置可选日期范围的选项,但您可以更改格式以使用两位数年份。
在您的屏幕截图中,我可以看到,您正在使用“到达日期”的日期选择器,我认为这是在未来。在网站上有一个关于如何禁用过去日期的示例。
希望对你有帮助。
更新
我已经为您的问题编写了一个事件处理程序,应该可以解决问题。
http://jsfiddle.net/pCYbd/1/ 上的 JavaScript
$("#dp").datepicker();
$("#dp").on("keyup", function(e) {
var date, day, month, newYear, value, year;
value = e.target.value;
if (value.search(/(.*)\/(.*)\/(.*)/) !== -1) {
date = e.target.value.split("/");
month = date[0];
day = date[1];
year = date[2];
if (year === "") {
year = "0";
}
if (year.length < 4) {
newYear = String(2000 + parseInt(year));
$(this).datepicker("setValue", "" + month + "/" + day + "/" + newYear);
if (year === "0") {
year = "";
}
return $(this).val("" + month + "/" + day + "/" + year);
}
}
});
http://jsfiddle.net/pCYbd/2/ 上的 CoffeeScript
$("#dp").datepicker()
$("#dp").on "keyup", (e) ->
value = e.target.value
if value.search(/(.*)\/(.*)\/(.*)/) != -1
date = value.split("/")
month = date[0]
day = date[1]
year = date[2]
year = "0" if year == ""
if year.length < 4
newYear = String(2000 + parseInt(year))
$(@).datepicker("setValue", "#{month}/#{day}/#{newYear}")
year = "" if year == "0"
$(@).val("#{month}/#{day}/#{year}")
我的 JavaScript 技能不是最好的,但这应该可以。