我已按照以下脚本将日历绑定到文本框。
@日历脚本@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" />
Include Bootstrap Datepicker
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
$(document).ready(function () {
$(".getdate").each(function () {
$(this).datepicker(
{
changeYear: true,
format: 'dd MM yy',
todayHighlight: true,
autoclose: true
});
});
});
@Html.TextBoxFor(m => m.ProjectFromDate, "{0:dd/MM/yy}", new { @id = "txtProjectFromDate", @Value = @ViewBag.ProjectFromDate, @class = "getdate" })
在页面加载时,如果单击文本框,则会显示日历。但是如果选择日期,年份会减少。例如,如果我在文本框中选择 10-DEC-2021,它将显示为 10-DEC-1921。
让我知道我错过了什么。
提前致谢。