Change background color of a specific a day in a jquery datepicker

房东的猫 提交于 2019-12-04 04:07:50

问题


I want to know how to set background color on the dates in a datePicker; I followed a lot of tutorials but I didn`t get any result.

I have this datePicker:

<div id="datepicker"></div>

回答1:


Just in case Mongoose's link goes bad someday it is best to post full answers here on StackOverflow:

Here is a working code snippet and screenshot of what the datepicker looks like using the beforeShowDay function of the jQueryUI datepicker:

$(document).ready(function() {
    var SelectedDates = {};
    SelectedDates[new Date('04/05/2016')] = new Date('04/05/2016');
    SelectedDates[new Date('05/04/2017')] = new Date('05/04/2017');
    SelectedDates[new Date('06/06/2018')] = new Date('06/06/2018');

    $('#txtDate').datepicker({
        beforeShowDay: function(date) {
            var Highlight = SelectedDates[date];
            if (Highlight) {
                return [true, "Highlighted", Highlight];
            }
            else {
                return [true, '', ''];
            }
        }
    });
});
body
{
    font-family:Arial;
    font-size : 10pt;
    padding:5px;
}

.Highlighted a{
   background-color : Green !important;
   background-image :none !important;
   color: White !important;
   font-weight:bold !important;
   font-size: 12pt;
}
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>

<input type='text' id='txtDate' />

fiddle: http://jsfiddle.net/jquerybyexample/cqf9d/?utm_source=website&utm_medium=embed&utm_campaign=cqf9d

Documentation: Jquery ui documentation on beforeShowDay



来源:https://stackoverflow.com/questions/12944853/change-background-color-of-a-specific-a-day-in-a-jquery-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!