我正在尝试突出日期选择器中的日期。我正在使用下面的代码突出显示它们。但要突出显示日期选择器的所有日子。
dates.data = ['0','1','2'] // days of week
beforeShowDay: function (date) {
if($.inArray(date.getDay(), dates.data)) {
// if it is return the following.
return [true, 'ui-state-error', 'tooltip text'];
} else {
// default
return [true, '', ''];
}
}
您可以将bdeforeShowDay函数与荧光笔css一起使用。
var highlightDays = ["2020-2-21","2020-2-23","2020-2-11","2020-3-21",];
var date = new Date();
jQuery(document).ready(function() {
$( "#datepicker").datepicker({
dateFormat: 'yy-mm-dd',
beforeShowDay: function(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < highlightDays.length; i++) {
if($.inArray(y + '-' + (m+1) + '-' + d,highlightDays) != -1) {
return [true, 'highlight', ''];
}
}
return [true];
}
});
});
.highlight{
background-color: red;
}
<html lang="en">
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" /></p>
</body>
</html>
var highlight_dates = {};
highlight_dates[ new Date( '03/10/2020' )] = new Date( '03/10/2020' );
highlight_dates[ new Date( '02/21/2020' )] = new Date( '02/21/2020' );
$('#datepicker').datepicker({
beforeShowDay: function(date) {
var highlight = highlight_dates[date];
if( highlight ) {
return [true, "class-to-highlight", 'Special Event'];
} else {
return [true, '', ''];
}
}
});
.class-to-highlight{
background-color: #ff0;
}
<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>
<p>Date: <input type="text" id="datepicker"></p>