在jquery ui datepicker中,无论如何在OnSelect()事件上都可以获取先前选择的日期 [英] in jquery ui datepicker, on the OnSelect() event is there anyway to get the previous selected date
本文介绍了在jquery ui datepicker中,无论如何在OnSelect()事件上都可以获取先前选择的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 jquery ui datepicker 的 onSelect 事件上具有代码现在我只想在日期已更改值的情况下运行我的函数(因此,如果用户选择文本框中已经存在的日期,则我不想运行此代码,因为这将是多余的计算).这是我现有的代码.
i have code on the onSelect event of the jquery ui datepicker and i now want to only run my function if the date has changed values (so if a user selects a date that was already there in the textbox, i don't want to run this code as it will be a redundant calculation). Here is my existing code.
$('#Milestone').datepicker({
dateFormat: 'dd M yy',
onSelect: calcUpdate
});
推荐答案
您可以使用数据存储以前存储的值,并将当前值与其进行比较.
You can use data to store previously stored value and compare the current value to it.
尝试以下操作(将这些语句放入文档准备事件中):
Try this(put these statements in your document ready event):
$('#Milestone').data("prev", $(this).val());
$('#Milestone').datepicker({
dateFormat: 'dd M yy',
onSelect: function(dateText){
var prevDate = $(this).data("prev")
var curDate = dateText;
if(prevDate == curDate){
$(this).data("prev", curDate)
calcUpdate();
}
}
});
这篇关于在jquery ui datepicker中,无论如何在OnSelect()事件上都可以获取先前选择的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文