如何通过给出两个日期来限制jQuery Datepicker的日期范围? [英] How to restrict date range of a jquery datepicker by giving two dates?
问题描述
我有两个存储在数据库中的日期,并使用$ .ajax()选择它,我需要显示从数据库中选择的日期之间的datepicker值.
I am having two dates that is stored in db and am selecting it using $.ajax() and what i need is to show the datepicker values between the dates I selected from db.
这是我的代码.但是它不能正常工作
Here is my code for it.But it is not working properly
function setDatePickerSettings(isFisc) {
var fSDate, fEDate;
$.ajax({
type: "POST",
url: '../Asset/Handlers/AjaxGetData.ashx?fisc=1',
success: function(data) {
alert(data);
var res = data.split("--");//data will be 4/4/2010 12:00:00--5/4/2011 12:00:00
var sDate = res[0].split(getSeparator(res[0]));
alert("Separator " + getSeparator(res[1]) + " Starts " + sDate);
var eDate = res[1].split(getSeparator(res[1]));
alert("End " + eDate);
alert("sub " + sDate[0]);
fSDate = new Date(sDate[2].substring(0, 4), sDate[0], sDate[1]);
alert("Starts " + fSDate.substring(0, 4));
fEDate = new Date(eDate[2].substring(0, 4), eDate[0], eDate[1]);
alert("eND " + fEDate.toString());
}
});
var dtSettings = {
changeMonth: true,
changeYear: true,
showOn: 'both',
buttonImage: clientURL + 'images/calendar.png',
buttonImageOnly: true,
showStatus: true,
showOtherMonths: false,
dateFormat: 'dd/mm/yy',
minDate:fSDate, //assigning startdate
maxDate:fEDate //assigning enddate
};
return dtSettings;
}
请提供一些解决方案.我需要datetime选择器,该选择器需要该范围之间的值.预先感谢
Pls provide some solution. I need the datetime picker which requires values between that range. Thanks in advance
推荐答案
您的语法对于minDate/maxDate是错误的. 您可以在演示所在的jQuery UI网站上阅读文档.我建议您看一下它,以使其适合您的特定情况.看起来像这样:
Your syntax is wrong for the minDate/maxDate. You can read the documentation on the jQuery UI website where the demo is. I suggest you take a look at it to tailor it to your specific case. It looks something like this:
$( ".selector" ).datepicker({ minDate: new Date(2007, 1 - 1, 1) });
或
以下内容将使您无法选择今天之前的任何内容.
the following will make it so that you can't pick anything previous to today.
$( ".selector" ).datepicker({ minDate: 0 });
这将使它成为可能,所以您明天之前就不能选择任何东西
and this will make it so you can't pick anything before tomorrow
$( ".selector" ).datepicker({ maxDate: 1 });
这是您插入自己的日期的方式,但是我在使dateFormat正常工作方面遇到问题,如您所见,我指定了dateFormat,但实际上输入的格式却忽略了dateformat.
Here is how you insert your own date, but i'm having an issue getting the dateFormat to work correctly, as you can see I have the dateFormat specified, but the format I actually put in is ignoring the dateformat.
$("#txtDateStart").datepicker({dateFormat:'mm/dd/yy', minDate: new Date(2010,11,12) });
这篇关于如何通过给出两个日期来限制jQuery Datepicker的日期范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!