如何更改日期选择器的可选日期的背景颜色?

How to change background-color of selectable dates of datepicker?

嗨,我目前正在学习 jquery 和 javascript。大意是改jquery.ui的css.

您需要覆盖 jquery.ui

中的 css

您要找的选择器是

.ui-datepicker-calendar a {

}

您应该指定更多 css,以便使用您的自定义样式。否则使用 !important.

.ui-datepicker-calendar a {
    color:white !important;
    background-color:black !important;
}

像这样:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style>
body
{
    font-size:8pt;
    font-family:Verdana;
    padding: 5px;
}
  
.ui-datepicker-calendar a {
  color: white !important;
  background-color: black !important;
  border-color: black;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
</head>
<body>
    
<br/>
From: <input type="text" id="txtFromDate" />
To: <input type="text" id="txtToDate" />

<script type="text/javascript">
$(function(){
 $("#txtFromDate").datepicker({
  minDate:0,
  maxDate: "+60D",
  numberOfMonths: 2,
 });
 $("#txtToDate").datepicker({ 
  minDate:0,
  maxDate:"+60D",
  numberOfMonths: 2,
 }); 
 var default_date = new Date();
 default_date.setDate(default_date.getDate()+60);
 $('#txtFromDate').datepicker('setDate', new Date());
 $('#txtToDate').datepicker('setDate', default_date);
});
$("#txtFromDate").datepicker({
    onSelect: function(dateText) {
        $("#txtToDate").datepicker("option", "minDate", $('#txtFromDate').datepicker("getDate") );
        var date2 = $("#txtFromDate").datepicker("getDate");
        date2.setDate(date2.getDate()+60);
        $("#txtToDate").datepicker("option", "maxDate", date2);
    }
});
</script>

</body>
</html>