我有一个使用当前日期加载的日期选择器。但是,我试图找出如何确定用户选择的日期是否在当前日期之前并显示消息。我怎么能够做到这一点?谢谢!
function LoadSelectedEvents()
{
$.ajax({
type: 'GET',
url: fullURL,
dataType: 'xml',
beforeSend:
function () {
ShowLoading();
},
success:
function (xml) {
HideLoading();
//bring jquerypaging in
$.getScript("../js/jqueryPaging.js");
//initialize our datepicker
$("#datepickercalendar").datepicker({
dateFormat: 'DD, MM dd, yy',
minDate: 0,
onSelect: function (dateText, inst) {
var dateAsString = dateText;
var dateAsObject = $(this).datepicker('getDate');
$(".easyPaginateNav").empty();
//ajax call on user select
$.ajax({
type: 'GET',
url: fullURL,
dataType: 'xml',
beforeSend: function () {
ShowLoading();
$("#EventListHeaderDate").empty();
$("#feedContainer").empty();
},
complete: function () {
HideLoading();
},
success: function (xml) {
//clear results
$("#feedContainer").empty();
var index = 0;
$("#EventListHeaderDate").text(dateAsString);
//find each ITEM and display
$(xml).find("item").slice(0, maxItems).each(function () {
//find matches based on date
var title = $(this).find("title").text();
var itemDate = $(this).find("date").text();
var itemTime = $(this).find("time").text();
//alert(index);
if (dateText == itemDate) {
$("#feedContainer").fadeIn();
$("#feedContainer").append("<div id='event'>" + "<span id='event-title'>" + title + "</span><br>" +
"<span id='event-date'>" + itemDate + "</span><br>" + "<hr></div>" + "");
index++;
}
});
if (index == 0) {
$("#feedContainer").empty();
$("#feedContainer").append("No Events for this Date.");
}
$("#feedContainer").easyPaginate({
paginateElement: 'div#event',
elementsPerPage: 2,
effect: 'climb'
});
HideLoading();
}
});
}
//altField: "#EventListHeaderDate"
}); //end datepicker initialization
var index = 0;
//our current date of datepicker in a variable
var currentDate = $("#datepickercalendar").datepicker().val();
$('#EventListHeaderDate').text(currentDate); //update header to reflect current (todays) date
//parse XML
$(xml).find("item").slice(0, maxItems).each(function () {
//find matches based on date
var title = $(this).find("title").text();
var itemDate = $(this).find("date").text();
var itemTime = $(this).find("time").text();
if (currentDate == itemDate) {
index++;
//alert(index);
$("#feedContainer").fadeIn();
$("#feedContainer").append("<div id='event'>" + "<span id='event-title'>" + title + "</span><br>" +
"<span id='event-date'>" + itemDate + "</span><br>" + "</div>" + "<hr>");
}
});
if (index == 0) {
$("#feedContainer").empty();
$("#feedContainer").append("No Events for this Date.");
}
//and paginate the results
$("#feedContainer").easyPaginate({
paginateElement: 'div#event',
elementsPerPage: 2,
effect: 'climb'
});
},
error: function () { $("#loading").replaceWith("Error: Could not fetch events"); }
}); //end first ajax
}
答案 0 :(得分:0)
你应该注意用户,但正如你所说,你不想这样做 HTML代码
<input id='datapicker' value="06/15/2016">
java脚本代码
<script>
function data_checker(){
var input_data= $("#datapicker").val();
if(Date.parse(input_data)-Date.parse(new Date()) < 0){
alert("data too old");
}
}
data_checker();
</script>