我正在创建一个页面datepicker
并获取两个日期范围之间的所有日期。
我希望它显示在 a 中listbox
并使每个日期列表可点击。那可能吗?
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Select a Date Range</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-
ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$("#from").datepicker();
$("#to").datepicker();
$('#getBetween').on('click', function () {
var start = $("#from").datepicker("getDate"),
end = $("#to").datepicker("getDate"),
currentDate = new Date(start),
between = []
;
while (currentDate <= end) {
between.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
$('#results').html(between.join('<br> '));
});
});
</script>
</head>
<body>
<input id="from" />
<input id="to" />
<button id="getBetween">Get Between Dates</button>
<ul>
<li id="results" ></li>
</ul>
</body>
</html>