Jquery 日期选择器 select 突出显示月份
Jquery date picker select highlighted month
我有一个日期选择器,我在这里突出显示 selected period.But 我在这里有一些问题,那就是
这是 2017 年 1 月,但是当我 select 2 月的某个时期时,它被正确地突出显示在
2 月但默认显示当前月份 int datepicker,即 1 月。
代码
$("#daterangepicker1").datepicker({
inline: true,
beforeShowDay: function(date) {
var theday = (date.getMonth() + 1) + '/' +
date.getDate() + '/' +
date.getFullYear();
return [true, $.inArray(theday, dtrange) >= 0 ? "hightlight" : ''];
}
});
如果需要打开日期选择器jQuery Date picker from a specific month, you need to set the defaultDate。根据您的要求,您需要将二月的任何一天设置为日期选择器的默认日期。这是一个示例代码片段。此处将 2 月的 3 天设置为默认选择,并将 2 月 1 日设置为默认日期。因此,您的日历从 2017 年 2 月开始。
这是一个示例片段
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.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>
<style>
.hightlight {
background: green;
}
</style>
<script>
$(function () {
$("#daterangepicker1").datepicker({
inline: true,
defaultDate: new Date("2/1/2017"),
beforeShowDay: function (date) {
var dtrange = ["2/2/2017", "2/12/2017", "2/22/2017"];
var theday = (date.getMonth() + 1) + '/' +
date.getDate() + '/' +
date.getFullYear();
return [true, $.inArray(theday, dtrange) >= 0 ? "hightlight" : ''];
}
});
});
</script>
</head>
<body>
<p>Date:
<input type="text" id="daterangepicker1">
</p>
</body>
</html>
我有一个日期选择器,我在这里突出显示 selected period.But 我在这里有一些问题,那就是 这是 2017 年 1 月,但是当我 select 2 月的某个时期时,它被正确地突出显示在 2 月但默认显示当前月份 int datepicker,即 1 月。
代码
$("#daterangepicker1").datepicker({
inline: true,
beforeShowDay: function(date) {
var theday = (date.getMonth() + 1) + '/' +
date.getDate() + '/' +
date.getFullYear();
return [true, $.inArray(theday, dtrange) >= 0 ? "hightlight" : ''];
}
});
如果需要打开日期选择器jQuery Date picker from a specific month, you need to set the defaultDate。根据您的要求,您需要将二月的任何一天设置为日期选择器的默认日期。这是一个示例代码片段。此处将 2 月的 3 天设置为默认选择,并将 2 月 1 日设置为默认日期。因此,您的日历从 2017 年 2 月开始。
这是一个示例片段
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.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>
<style>
.hightlight {
background: green;
}
</style>
<script>
$(function () {
$("#daterangepicker1").datepicker({
inline: true,
defaultDate: new Date("2/1/2017"),
beforeShowDay: function (date) {
var dtrange = ["2/2/2017", "2/12/2017", "2/22/2017"];
var theday = (date.getMonth() + 1) + '/' +
date.getDate() + '/' +
date.getFullYear();
return [true, $.inArray(theday, dtrange) >= 0 ? "hightlight" : ''];
}
});
});
</script>
</head>
<body>
<p>Date:
<input type="text" id="daterangepicker1">
</p>
</body>
</html>