我需要有日期选择器(已以芬兰语本地化),可以在1996年1月1日至2015年12月31日之间选择日期。用户选择日期后,所选的日期将显示在p
元素中。 p
在开始的文本中显示:“尚未选择日期”。从“日期选择器”中选择日期后,此文本消失,并且在同一p
元素中以红色字体显示选择的日期。所以...
Datepicker到目前为止运行良好,但是如何将日历中的最后日期更改为2015年12月31日,而不是2015年11月31日?我尝试从此处检查示例,但无法完美完成:https://jqueryui.com/datepicker/#min-max
选择日期后,如何使p
中的文本消失(隐藏),并用选择的日期替换为红色字体?
到目前为止是我的代码。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Populate alternate field</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<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 type="text/javascript" src="finnish.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker({
altField: "#alternate",
altFormat: "DD, d MM, yy",
minDate: (new Date(1996, 1-1, 1)),
maxDate: (new Date(2015, 12-12, 31))
});
$.datepicker.setDefaults(
$.extend(
{'dateFormat':'dd-mm-yy'},
$.datepicker.regional['fi']
)
);
} );
//I should work on this, but how?
$( "#datepicker" ).on( "click", function() {
hide();
});
</script>
</head>
<body>
<p id="text">The date is not chosen yet<input type="text" id="datepicker"> <input type="text" id="alternate" size="30"></p>
</body>
</html>
尝试此JQuery:
$( function() {
$( "#datepicker" ).datepicker({
dateFormat: "DD, d MM, yy",
minDate: (new Date(1996, 1-1, 1)),
maxDate: (new Date(2015, 12-1, 31)),
onSelect: function(){
var selected = $(this).val();
$("#result").html(selected).css('color', 'red');
}
});
} );
和HTML正文:
<p id="result">The date is not chosen yet</p>
Select date here:<input type="text" id="datepicker">