我使用 jquery ui 创建了一个日历控件,对要选择的日期有一些限制。我的要求是在禁用日期上显示工具提示,例如“抱歉,此日期不可选择”。有没有办法解决这个问题?PFB我的代码:
<!doctype html>
<html><head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker </title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
</script> <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js">
</script>
<script>
$(function () {
$("#datepicker").datepicker({
minDate: -0,
maxDate: "+1M +2D",
showOn: "button",
buttonImage: "calendar.png",
buttonImageOnly: true,
dateFormat: 'D dd MM yy',
showAnim: "clip"
});
$("#datepicker").change(function () {
updateDate();
});
$("#addDate").click(function () {
addDaysToDate();
});
$("#subtractDate").click(function () {
subtractDaysToDate();
});
});
function updateDate() {
var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate() + 1);
var date2 = $('#datepicker').datepicker('getDate');
date2.setHours(0,0,0,0);
today.setHours(0,0,0,0);
tomorrow.setHours(0,0,0,0);
if (date2.getTime() == today.getTime()) {
//document.getElementById('datepicker').value=document.getElementById('datepicker').value+" (TODAY)";
$('#datepicker').val($('#datepicker').val() + " (TODAY)");
} else if (date2.getTime() == tomorrow.getTime()) {
//document.getElementById('datepicker').value=document.getElementById('datepicker').value+" (TOMORROW)";
$('#datepicker').val($('#datepicker').val() + " (TOMORROW)");
} else {
$('#datepicker').text("");
}
}
function addDaysToDate() {
var date2 = $('#datepicker').datepicker('getDate');
date2.setDate(date2.getDate() + 1);
$('#datepicker').datepicker('setDate', date2);
$('#datepicker').change();
}
function subtractDaysToDate() {
var date2 = $('#datepicker').datepicker('getDate');
date2.setDate(date2.getDate() - 1);
$('#datepicker').datepicker('setDate', date2);
$('#datepicker').change();
}
</script>
</head>
<body>
<input type="image" id="subtractDate" src="datedecrementer.png" />
<input type="text" id="datepicker" style="width:220px;border:0" />
<input type="image" id="addDate" src="dateincrementer.png" />
</body></html>