如何设置指定的日期引导程序datepicker?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何设置指定的日期引导程序datepicker?相关的知识,希望对你有一定的参考价值。
我正在使用this bootstrap datepicker plugin并且我想为我指定的日子设置课程,例如我已经预订了几天,我想为我这些日子设置课程,但我不想解除他们如何做帽子?
$(document).ready(function() {
$('#date-range12').dateRangePicker({
inline: true,
container: '#date-range12-container',
alwaysOpen: true,
format: 'DD.MM.YYYY',
separator: ' to ',
language: 'tr',
showTopbar: false,
showWeekNumbers: false,
extraClass: 'date-range-picker19',
monthSelect: true,
yearSelect: true,
customArrowPrevSymbol: '<a href="#" class="fa-blok fa fa-arrow-circle-left"></a>',
customArrowNextSymbol: '<a href="#" class="fa-blok fa fa-arrow-circle-right"></a>',
//maxDays: 7,
//minDays: 3,
startDate: moment(),
startOfWeek: 'monday',
customTopBar: 'Tarih Aralığı Seçiniz',
showDateFilter: function(time, date) {
return '<div style="padding:0 5px;">
<span style="font-weight:bold">' + date + '</span>
<div style="opacity:0.3;">$' + Math.round(Math.random() * 999) + '</div>
</div>';
}
});
});
.date-picker {
width: 170px;
height: 25px;
padding: 0;
border: 0;
line-height: 25px;
padding-left: 10px;
font-size: 12px;
font-family: Arial, sans-serif;
font-weight: 700;
cursor: pointer;
color: #303030;
position: relative;
z-index: 2
}
.date-picker-wrapper {
position: absolute;
z-index: 1;
//border: 1px solid #bfbfbf;
background-color: #efefef;
//padding: 5px 12px;
font-size: 12px;
line-height: 20px;
color: #aaa;
font-family: Arial, sans-serif;
-webkit-box-shadow: 3px 3px 10px rgba(0, 0, 0, .5);
box-shadow: 3px 3px 10px rgba(0, 0, 0, .5);
-webkit-box-sizing: initial;
box-sizing: initial
}
.dp-clearfix {
clear: both;
height: 0;
font-size: 0
}
.date-picker-wrapper.inline-wrapper {
position: relative;
-webkit-box-shadow: none;
box-shadow: none;
display: inline-block
}
.date-picker-wrapper.single-date {
width: auto
}
.date-picker-wrapper.no-shortcuts {
//padding-bottom: 12px
}
.date-picker-wrapper.no-topbar {
//padding-top: 12px
}
.date-picker-wrapper .footer {
font-size: 11px;
//padding-top: 3px
}
.date-picker-wrapper b {
color: #666;
font-weight: 700
}
.date-picker-wrapper a {
color: #6bb4d6;
text-decoration: underline
}
.date-picker-wrapper .month-name {
text-transform: uppercase
}
.date-picker-wrapper .select-wrapper {
position: relative;
overflow: hidden;
display: inline-block;
vertical-align: middle
}
.date-picker-wrapper .select-wrapper:hover {
text-decoration: underline
}
.date-picker-wrapper .month-element {
display: inline-block;
vertical-align: middle
}
.date-picker-wrapper .select-wrapper select {
position: absolute;
margin: 0;
padding: 0;
left: 0;
top: -1px;
font-size: inherit;
font-style: inherit;
font-weight: inherit;
text-transform: inherit;
color: inherit;
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: 0 0;
border: 0;
outline: 0;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=1)";
filter: alpha(opacity=1);
opacity: .01
}
.date-picker-wrapper .month-wrapper {
border: 1px solid #bfbfbf;
//border-radius: 3px;
//background-color: #fff;
background-color: #d0d5de;
padding: 12px 12px 40px 12px;
cursor: default;
position: relative;
_overflow: hidden;
width:100% !important;
}
.date-picker-wrapper .month-wrapper table {
width: 190px;
float: left;
margin-right:20px;;
}
.date-picker-wrapper .month-wrapper table.month2 {
width: 190px;
float: left
}
.date-picker-wrapper .month-wrapper table td,
.date-picker-wrapper .month-wrapper table th {
vertical-align: middle;
text-align: center;
line-height: 14px;
margin: 0;
padding: 0;
color:#FFF;
font-weight: normal;
font-size: 14px;
}
.date-picker-wrapper .month-wrapper table .day {
//padding: 5px 0;
//line-height: 1;
//font-size: 12px;
//margin-bottom: 1px;
//color: #ccc;
//cursor: default;
line-height: 1;
font-size: 12px;
color: #ccc;
cursor: not-allowed;
padding: 15px;
border: 1px solid #eee;
background: #f0f0f0;
}
.date-picker-wrapper .month-wrapper table div.day.lastMonth,
.date-picker-wrapper .month-wrapper table div.day.nextMonth {
color: #999;
cursor: default
}
.date-picker-wrapper .month-wrapper table .week-name {
height: 40px;
line-height: 20px;
font-weight: 100;
text-transform: uppercase;
}
.date-picker-wrapper .month-wrapper table .day.has-tooltip {
cursor: help!important
}
.date-picker-wrapper .month-wrapper table .day.has-tooltip .tooltip {
white-space: nowrap
}
.date-picker-wrapper .time label {
white-space: nowrap;
}
.date-picker-wrapper .month-wrapper table .day.toMonth.valid {
color: #333;
cursor: pointer;
padding: 15px;
border: 1px solid #eee;
background: #FFF;
}
.date-picker-wrapper .month-wrapper table .day.lastMonth,
.date-picker-wrapper .month-wrapper table .day.nextMonth {
display: none
}
.date-picker-wrapper .month-wrapper table .day.real-today {
background-color: #ffe684
}
.date-picker-wrapper .month-wrapper table .day.real-today.checked,
.date-picker-wrapper .month-wrapper table .day.real-today.hovering {
background-color: #70ccd5
}
.date-picker-wrapper table .caption {
height: 40px;
background-color: #4d5567;
color: #CBCDD0;
padding: 13px 0px;
font-size: 15px;
text-align: center;
}
.date-picker-wrapper table .caption>th:first-of-type,
.date-picker-wrapper table .caption>th:last-of-type {
width: 27px;
}
.date-picker-wrapper table .caption .next,
.date-picker-wrapper table .caption .prev {
width:50px;
height:40px;
line-height:40px;
vertical-align: middle;
display:block;
cursor: pointer;
background:#667493;
}
.caption .next{
float:right;
}
.date-picker-wrapper table .caption .next:hover,
.date-picker-wrapper table .caption .prev:hover {
background-color: #ccc;
color: #fff
}
.date-picker-wrapper .gap {
position: relative;
z-index: 1;
width: 15px;
height: 100%;
background-color: red;
font-size: 0;
line-height: 0;
float: left;
top: -5px;
margin: 0 10px -10px;
visibility: hidden;
height: 0;
display:none;
}
.date-picker-wrapper .gap .gap-lines {
height: 100%;
overflow: hidden
}
.date-picker-wrapper .gap .gap-line {
height: 15px;
width: 15px;
position: relative
}
.date-picker-wrapper .gap .gap-line .gap-1 {
z-index: 1;
height: 0;
border-left: 8px solid #fff;
border-top: 8px solid #eee;
border-bottom: 8px solid #eee
}
.date-picker-wrapper .gap .gap-line .gap-2 {
position: absolute;
right: 0;
top: 0;
z-index: 2;
height: 0;
border-left: 8px solid transparent;
border-top: 8px solid #fff
}
.date-picker-wrapper .gap .gap-line .gap-3 {
position: absolute;
right: 0;
top: 8px;
z-index: 2;
height: 0;
border-left: 8px solid transparent;
border-bottom: 8px solid #fff
}
.date-picker-wrapper .gap .gap-top-mask {
width: 6px;
height: 1px;
position: absolute;
top: -1px;
left: 1px;
background-color: #eee;
z-index: 3
}
.date-picker-wrapper .gap .gap-bottom-mask {
width: 6px;
height: 1px;
position: absolute;
bottom: -1px;
left: 7px;
background-color: #eee;
z-index: 3
}
.date-picker-wrapper .selected-days {
display: none
}
.date-picker-wrapper .drp_top-bar {
line-height: 1.4;
position: relative;
padding: 10px 40px 10px 0
}
.date-picker-wrapper .drp_top-bar .error-top,
.date-picker-wrapper .drp_top-bar .normal-top {
display: none
}
.date-picker-wrapper .drp_top-bar .default-top {
display: block
}
.date-picker-wrapper .drp_top-bar.error .default-top {
display: none
}
.date-picker-wrapper .drp_top-bar.error .error-top {
display: block;
color: red
}
.date-picker-wrapper .drp_top-bar.normal .default-top {
display: none
}
.date-picker-wrapper .drp_top-bar.normal .normal-top {
display: block
}
.date-picker-wrapper .drp_top-bar.normal .normal-top .selection-top {
color: #333
}
.date-picker-wrapper .drp_top-bar .apply-btn {
position: absolute;
right: 0;
top: 6px;
padding: 3px 5px;
margin: 0;
font-size: 12px;
border-radius: 4px;
cursor: pointer;
color: #d9eef7;
border: solid 1px #0076a3;
background: #0095cd;
background: -moz-linear-gradient(top, #00adee, #0078a5);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00adee', endColorstr='#0078a5');
color: #fff;
line-height: initial
}
.date-picker-wrapper .drp_top-bar .apply-btn.disabled {
cursor: pointer;
color: #606060;
border: solid 1px #b7b7b7;
background: #fff;
background: -moz-linear-gradient(top, #fff, #ededed);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ededed')
}
.date-picker-wrapper .time {
position: relative
}
.date-picker-wrapper.single-month .time {
display: block
}
.date-picker-wrapper .time input[type=range] {
vertical-align: middle;
width: 129px;
padding: 0;
margin: 0;
height: 20px
}
.date-picker-wrapper .time1 {
width: 180px;
padding: 0 5px;
text-align: center
}
.time2 {
width: 180px;
padding: 0 5px;
text-align: center
}
.date-picker-wrapper .time1 {
float: left
}
.date-picker-wrapper .time2 {
float: right
}
.date-picker-wrapper .hour {
text-align: right
}
.minute {
text-align: right
}
.date-picker-wrapper .hide {
display: none
}
.date-picker-wrapper .date-range-length-tip {
position: absolute;
margin-top: -4px;
margin-left: -8px;
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, .3);
box-shadow: 0 0 3px rgba(0, 0, 0, .3);
display: none;
background-color: #ff0;
padding: 0 6px;
border-radius: 2px;
font-size: 12px;
line-height: 16px;
-webkit-filter: drop-shadow(0 0 3px rgba(0, 0, 0, .3));
-moz-filter: drop-shadow(0 0 3px rgba(0, 0, 0, .3));
-ms-filter: drop-shadow(0 0 3px rgba(0, 0, 0, .3));
-o-filter: drop-shadow(0 0 3px rgba(0, 0, 0, .3));
filter: drop-shadow(0 0 3px rgba(0, 0, 0, .3))
}
.date-picker-wrapper .date-range-length-tip:after {
content: '';
position: absolute;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 4px solid #ff0;
left: 50%;
margin-left: -4px;
bottom: -4px
}
.date-picker-wrapper.two-months.no-gap .month1 .next,
.date-picker-wrapper.two-months.no-gap .month2 .prev {
display: none
}
.date-picker-wrapper .week-number {
padding: 5px 0;
line-height: 1;
font-size: 12px;
margin-bottom: 1px;
color: #999;
cursor: pointer;
display:none;
}
.day.toMonth.valid div[style="padding:0 5px;"]{
padding:-1px !important;
}
.date-picker-wrapper .week-number.week-number-selected {
color: #49e;
font-weight: 700
}
.day.toMonth.valid div span,.day.toMonth.invalid div span {
font-weight: normal !important;
display: block;
margin-bottom: 12px;
font-size: 15px;
}
.day.toMonth.valid div span+div {
background: #4D5567;
color: #FFF;
opacity: 1 !important;
padding:7px 5px;
}
.day.toMonth.invalid div span{
opacity: 1 !important;
padding:7px 5px;
}
.week-name th:first-child{
color:transparent !important;
}
.day.toMonth.valid:hover {
background-color:#4499EE !important;
color: #fff !important
}
.date-picker-wrapper .month-wrapper table .checked {
background-color: #9cdbf7 !important;
}
.date-picker-wrapper.date-range-picker19 .day.first-date-selected { background-color: #4499EE !important;color:#FFF !important; }
.date-picker-wrapper.date-range-picker19 .day.last-date-selected { background-color: #4499EE !important; color:#FFF !important;}
.fa-blok{
display:inline;
color:#FFF !important;
text-decoration: none !important;
}
@media screen and (max-width: 660px) {
.date-picker-wrapper .month-wrapper table .day.toMonth.valid,.date-picker-wrapper .month-wrapper table .day.toMonth.invalid{
padding:8px;
}
.month1{
margin-bottom: 0px;
}
.date-picker-wrapper .month-wrapper table{
width:100%;
margin-right: 0;
float:none;
}
.date-picker-wrapper .month-wrapper table td, .date-picker-wrapper .month-wrapper table th{
font-size: 12px;
}
}
@media screen and (max-width: 490px) {
.day.toMonth.valid div span, .day.toMonth.invalid div span{
font-size: 12px;
margin-bottom: 7px;
}
.day.toMonth.valid div span+div{
padding:3px 2px;
}
.date-picker-wrapper .month-wrapper{
padding:0;
}
}
@media screen and (max-width: 446px) {
.day.toMonth.valid div span+div{
padding:3px 0;
}
.day.toMonth.valid div span, .day.toMonth.invalid div span{
font-size: 11px;
}
}
@media screen and (max-width: 400px) {
.date-picker-wrapper .month-wrapper table .day.toMonth.valid, .date-picker-wrapper .month-wrapper table .day.toMonth.invalid{
padding:5px 5px;
}
}
@media screen and (max-width: 320px) {
.day.toMonth.valid div span, .day.toMonth.invalid div span{
font-size: 10px;
margin-bottom: 12px;
}
.date-picker-wrapper .month-wrapper table .day.toMonth.valid, .date-picker-wrapper .month-wrapper table .day.toMonth.invalid{
padding:2px 0;
}
.day.toMonth.valid div span+div{
font-size: 11px;
}
}
.reserved{
position: relative;
overflow: hidden;
}
.reserved:before{
content: "";
display: block;
position: absolute;
z-index: 10;
background: #551A62;
opacity: 0.7;
width: 100%;
height: 56%;
top: -4px;
transform: rotate(116deg);
overflow: hidden;
left: -43px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-date-range-picker/0.16.1/daterangepicker.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.16.0/moment.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-date-range-picker/0.16.1/jquery.daterangepicker.min.js"></script>
<input type="hidden" id="date-range12" size="40" value="">
<div id="date-range12-container" style="width:100%;"></div>
答案
您可以使用showDateFilter
方法来标识要添加自定义class
的日期。请参阅下面的exaple。这里需要突出显示的日期是highlightdates
数组。
请注意,执行showDateFilter
过滤器以识别日历中每个日期单元格的内容。
var highlightdates = [moment('22.12.2017', 'DD.MM.YYYY'), moment('24.01.2018', 'DD.MM.YYYY')]
$(document).ready(function () {
$('#date-range12').dateRangePicker(
{
inline: true,
container: '#date-range12-container',
alwaysOpen: true,
format: 'DD.MM.YYYY',
separator: ' to ',
language: 'tr',
showTopbar: false,
showWeekNumbers: false,
extraClass: 'date-range-picker19',
monthSelect: true,
yearSelect: true,
customArrowPrevSymbol: '<a href="#" class="fa-blok fa fa-arrow-circle-left"></a>',
customArrowNextSymbol: '<a href="#" class="fa-blok fa fa-arrow-circle-right"></a>',
//maxDays: 7,
//minDays: 3,
startDate: moment(),
startOfWeek: 'monday',
customTopBar: 'Tarih Aralığı Seçiniz',
showDateFilter: function (time, date) {
var doHighlight = highlightdates.some(function(item) {
return (item.isSame(moment(time), 'day') && item.isSame(moment(time), 'month') && item.isSame(moment(time), 'year'))
})
return '<div ' + (doHighlight ? 'class="highlight"' : '') + ' style="padding:0 5px;">
<span style="font-weight:bold">'+ date + '</span>
<div style="opacity:0.3;">$'+ Math.round(Math.random() * 999) + '</div>
</div>';
}
});
});
.highlight {
background-color: red;
}
.date-picker {
width: 170px;
height: 25px;
padding: 0;
border: 0;
line-height: 25px;
padding-left: 10px;
font-size: 12px;
font-family: Arial, sans-serif;
font-weight: 700;
cursor: pointer;
color: #303030;
position: relative;
z-index: 2
}
.date-picker-wrapper {
position: absolute;
z-index: 1;
//border: 1px solid #bfbfbf;
background-color: #efefef;
//padding: 5px 12px;
font-size: 12px;
line-height: 20px;
color: #aaa;
font-family: Arial, sans-serif;
-webkit-box-shadow: 3px 3px 10px rgba(0, 0, 0, .5);
box-shadow: 3px 3px 10px rgba(0, 0, 0, .5);
-webkit-box-sizing: initial;
box-sizing: initial
}
.dp-clearfix {
clear: both;
height: 0;
font-size: 0
}
.date-picker-wrapper.inline-wrapper {
position: relative;
-webkit-box-shadow: none;
box-shadow: none;
display: inline-block
}
.date-picker-wrapper.single-date {
width: auto
}
.date-picker-wrapper.no-shortcuts {
//padding-bottom: 12px
}
.date-picker-wrapper.no-topbar {
//padding-top: 12px
}
.date-picker-wrapper .footer {
font-size: 11px;
//padding-top: 3px
}
.date-picker-wrapper b {
color: #666;
font-weight: 700
}
.date-picker-wrapper a {
color: #6bb4d6;
text-decoration: underline
}
.date-picker-wrapper .month-name {
text-transform: uppercase
}
.date-picker-wrapper .select-wrapper {
position: relative;
overflow: hidden;
display: inline-block;
vertical-align: middle
}
.date-picker-wrapper .select-wrapper:hover {
text-decoration: underline
}
.date-picker-wrapper .month-element {
display: inline-block;
vertical-align: middle
}
.date-picker-wrapper .select-wrapper select {
position: absolute;
margin: 0;
padding: 0;
left: 0;
top: -1px;
font-size: inherit;
font-style: inherit;
font-weight: inherit;
text-transform: inherit;
color: inherit;
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: 0 0;
border: 0;
outline: 0;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=1)";
filter: alpha(opacity=1);
opacity: .01
}
.date-picker-wrapper .month-wrapper {
border: 1px solid #bfbfbf;
//border-radius: 3px;
//background-color: #fff;
background-color: #d0d5de;
padding: 12px 12px 40px 12px;
cursor: default;
position: relative;
_overflow: hidden;
width:100% !important;
}
.date-picker-wrapper .month-wrapper table {
width: 190px;
float: left;
margin-right:20px;;
}
.date-picker-wrapper .month-wrapper table.month2 {
width: 190px;
float: left
}
.date-picker-wrapper .month-wrapper table td,
.date-picker-wrapper .month-wrapper table th {
vertical-align: middle;
text-align: center;
line-height: 14px;
margin: 0;
padding: 0;
color:#FFF;
font-weight: normal;
font-size: 14px;
}
.date-picker-wrapper .month-wrapper table .day {
//padding: 5px 0;
//line-height: 1;
//font-size: 12px;
//margin-bottom: 1px;
//color: #ccc;
//cursor: default;
line-height: 1;
font-size: 12px;
color: #ccc;
cursor: not-allowed;
padding: 15px;
border: 1px solid #eee;
background: #f0f0f0;
}
.date-picker-wrapper .month-wrapper table div.day.lastMonth,
.date-picker-wrapper .month-wrapper table div.day.nextMonth {
color: #999;
cursor: default
}
.date-picker-wrapper .month-wrapper table .week-name {
height: 40px;
line-height: 20px;
font-weight: 100;
text-transform: uppercase;
}
.date-picker-wrapper .month-wrapper table .day.has-tooltip {
cursor: help!important
}
.date-picker-wrapper .month-wrapper table .day.has-tooltip .tooltip {
white-space: nowrap
}
.date-picker-wrapper .time label {
white-space: nowrap;
}
.date-picker-wrapper .month-wrapper table .day.toMonth.valid {
color: #333;
cursor: pointer;
padding: 15px;
border: 1px solid #eee;
background: #FFF;
}
.date-picker-wrapper .month-wrapper table .day.lastMonth,
.date-picker-wrapper .month-wrapper table .day.nextMonth {
display: none
}
.date-picker-wrapper .month-wrapper table .day.real-today {
background-color: #ffe684
}
.date-picker-wrapper .month-wrapper table以上是关于如何设置指定的日期引导程序datepicker?的主要内容,如果未能解决你的问题,请参考以下文章