Hai iam在这里创建一个带有datepicker的页面iam让所有日期都在两个日期之间 在列表视图中
但实际上我希望它显示在一个列表框中,并使每个日期列表可点击。它可能..ma code is
<!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>
提前致谢
答案 0 :(得分:1)
您可以更改此行:
between.push(new Date(currentDate));
到此:
between.push('<a href="#">' + new Date(currentDate) + '</a>');
我已经改变了你的html一点点。我取了ul
的ID并将其设为空( without any list items
)
<ul id="results" ></ul>
还有一些变化:
between.push('<li>' + new Date(currentDate) + '</li>');
点击事件隐藏其他列表项并在那里显示文本输入:
$(document).on('click', '#results li', function(){
$(this).siblings('li').hide().end().append('<input type="text" />');
}).on('click', '#results input', function(e){
e.stopPropagation(); // <---stops the event to buble up
});