我已经调试过了,这是你的问题:
var dateTimeFormat = 'j F Y G \h i \m\i\n';
您可能希望至少将\n 替换为n,但整个格式对我来说似乎无效。
之所以出现问题,是因为插件从格式创建代码作为字符串,然后在其上调用eval(),这显然是一种不好的做法。当您将\n 作为格式的一部分传递时,它会转换为↵(换行符)。它会破坏代码,因为它在字符串中,如下所示:
Date.prototype.format2 = function() { ... + '
';}
我建议你使用这个库的更新版本(也许他们已经修复了它):https://xdsoft.net/jqplugins/datetimepicker/
并考虑切换到一些更常见的日期格式,例如Y/m/d H:i。
我找不到有关您的插件格式的文档,因此您至少可以检查源以查看您可以在 dateTimeFormat 中使用的所有可用字母:
Date.getFormatCode = function(a) {
switch (a) {
case "d":
return "String.leftPad(this.getDate(), 2, '0') + ";
case "D":
return "Date.dayNames[this.getDay()].substring(0, 3) + ";
case "j":
return "this.getDate() + ";
case "l":
return "Date.dayNames[this.getDay()] + ";
case "S":
return "this.getSuffix() + ";
case "w":
return "this.getDay() + ";
case "z":
return "this.getDayOfYear() + ";
case "W":
return "this.getWeekOfYear() + ";
case "F":
return "Date.monthNames[this.getMonth()] + ";
case "m":
return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
case "M":
return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
case "n":
return "(this.getMonth() + 1) + ";
case "t":
return "this.getDaysInMonth() + ";
case "L":
return "(this.isLeapYear() ? 1 : 0) + ";
case "Y":
return "this.getFullYear() + ";
case "y":
return "('' + this.getFullYear()).substring(2, 4) + ";
case "a":
return "(this.getHours() < 12 ? 'am' : 'pm') + ";
case "A":
return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
case "g":
return "((this.getHours() %12) ? this.getHours() % 12 : 12) + ";
case "G":
return "this.getHours() + ";
case "h":
return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";
case "H":
return "String.leftPad(this.getHours(), 2, '0') + ";
case "i":
return "String.leftPad(this.getMinutes(), 2, '0') + ";
case "s":
return "String.leftPad(this.getSeconds(), 2, '0') + ";
case "O":
return "this.getGMTOffset() + ";
case "T":
return "this.getTimezone() + ";
case "Z":
return "(this.getTimezoneOffset() * -60) + ";
default:
return "'" + String.escape(a) + "' + ";
}
}
另外,您的 js 文件编码似乎有一些问题,您应该检查一下并切换到 UTF-8,可能。但这超出了问题范围。
现在,只需更改索引页面上的 dateTimeFormat 变量即可。