有没有人如何在我的jquery代码中更改日期格式。默认情况下,它使用mm / dd / yy 我想要yy / mm / dd
代码:
tjq('.datepicker-wrap input').datepicker({
showOn: 'button',
buttonImage: 'images/icon/blank.png',
buttonText: '',
buttonImageOnly: true,
/*showOtherMonths: true,*/
minDate: 0,
dayNamesMin: ["S", "M", "T", "W", "T", "F", "S"],
beforeShow: function(input, inst) {
var themeClass = tjq(input).parent().attr("class").replace("datepicker-wrap", "");
tjq('#ui-datepicker-div').attr("class", "");
tjq('#ui-datepicker-div').addClass("ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all");
tjq('#ui-datepicker-div').addClass(themeClass);
}
});
感谢您的时间。
答案 0 :(得分:0)
Hay你可以这样做,只需添加此选项并阅读officail docu。http://api.jqueryui.com/datepicker/#utility-formatDate
dateFormat: 'yy-mm-dd'
tjq('.datepicker-wrap input').datepicker({
showOn: 'button',
dateFormat: 'yy-mm-dd',
buttonImage: 'images/icon/blank.png',
buttonText: '',
buttonImageOnly: true,
/*showOtherMonths: true,*/
minDate: 0,
dayNamesMin: ["S", "M", "T", "W", "T", "F", "S"],
beforeShow: function(input, inst) {
var themeClass = tjq(input).parent().attr("class").replace("datepicker-wrap", "");
tjq('#ui-datepicker-div').attr("class", "");
tjq('#ui-datepicker-div').addClass("ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all");
tjq('#ui-datepicker-div').addClass(themeClass);
}
});
答案 1 :(得分:0)
您可以在初始化datepicker
时通过发送来覆盖默认日期格式。您可以在我的代码段中看到一个示例。看看jQuery API for the datepicker for more info
$('input').datepicker({
//showOn: 'button',
//buttonImage: 'images/icon/blank.png',
//buttonText: '',
//buttonImageOnly: true,
//showOtherMonths: true,
minDate: 0,
dateFormat: "yy/mm/dd",
dayNamesMin: ["S", "M", "T", "W", "T", "F", "S"],
beforeShow: function (input, inst)
{
//var themeClass = tjq(input).parent().attr("class").replace("datepicker-wrap", "");
//tjq('#ui-datepicker-div').attr("class", "");
//tjq('#ui-datepicker-div').addClass("ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all");
//tjq('#ui-datepicker-div').addClass(themeClass);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<input />