我有一个日期选择器,我想对其应用自定义格式,但是它不起作用。
$(function () {
$('.datepicker').datepicker({
dateFormat: "dd-mm-yy"
});
})
但是自定义格式未应用,它保留默认的“ mm / dd / yy”
任何线索还能对作法产生影响吗?它是带有EF的旧mvc .net项目。某些EF标签会影响吗?
非常感谢您的帮助
谢谢!
完整示例在此处,其中包含您需要的格式:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Format date</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$("#datepicker").datepicker();
$("#format").on( "change", function() {
$("#datepicker").datepicker( "option", "dateFormat", $( this ).val() );
});
} );
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" size="30"></p>
<p>Format options:<br>
<select id="format">
<option value="mm/dd/yy">Default - mm/dd/yy</option>
<option value="yy-mm-dd">ISO 8601 - yy-mm-dd</option>
<option value="dd-mm-yy">Other - dd-mm-yy</option>
<option value="d M, y">Short - d M, y</option>
<option value="d MM, y">Medium - d MM, y</option>
<option value="DD, d MM, yy">Full - DD, d MM, yy</option>
<option value="'day' d 'of' MM 'in the year' yy">With text - 'day' d 'of' MM 'in the year' yy</option>
</select>
</p>
</body>
</html>
可能失败的原因之一是,如果您在同一文件中两次调用datepicker()
,而一个正在覆盖另一个的结果。
HTML
<html>
<body>
<input type="text" class="datepicker">
</body>
</html>
JS
$(function () {
$('.datepicker').datepicker({
dateFormat: "dd-mm-yy"
}); // Initialized once
});
$('.datepicker').datepicker(); // Initialized again without any options
感谢输入专家,但我发现了问题-事实证明,该解决方案中存在另一个干扰jQuery UI库的js库,称为bootstrap-datepicker.js。对不起,不好的问题