我正在使用js datepicker来显示日历。
http://javascriptcalendar.org/javascript-date-picker.php
function initialize()
{
new JsDatePick({
useMode:2,
limitToToday :false,
target:"deadlinedate",
dateFormat:"%d-%m-%Y"
});
}
有没有办法在当前日期之前禁用所有日期。 任何帮助将不胜感激。
由于
答案 0 :(得分:2)
下载完整版而不是最小版,并在所有3个ifs中更改JsDatePick.prototype.isAvailable
>
函数<
答案 1 :(得分:1)
您可以将startDate和finishDate参数添加到jsDatePick。此库中有一个“limitToToday”控制语句(jsDatePick.full.1.x.js),您可以在此语句后添加2个控制语句,如下所示:
if (this.oConfiguration.limitToToday){
if ( ! this.isAvailable(this.currentYear, this.currentMonth, parseInt(oDay.getDate()) - 1 ) ){
disabledDayFlag = true;
aDayDiv.setAttribute("isJsDatePickDisabled",1);
}
}
//你的startDate方法
if (this.oConfiguration.startDate != ''){
startDate2 = new Date(Date.parse(this.oConfiguration.startDate));
if ( (oDay.getFullYear() < startDate2.getFullYear()) ||
(oDay.getFullYear() == startDate2.getFullYear() && oDay.getMonth() < startDate2.getMonth()) ||
(oDay.getFullYear() == startDate2.getFullYear() && oDay.getMonth() == startDate2.getMonth() && oDay.getDate() < startDate2.getDate() )
)
{
disabledDayFlag = true;
aDayDiv.setAttribute("isJsDatePickDisabled",1);
}
}
//你的finisDate方法
if (this.oConfiguration.finishDate != ''){
finishDate2 = new Date(Date.parse(this.oConfiguration.finishDate));
if ( (oDay.getFullYear() > finishDate2.getFullYear()) ||
(oDay.getFullYear() == finishDate2.getFullYear() && oDay.getMonth() > finishDate2.getMonth()) ||
( oDay.getFullYear() == finishDate2.getFullYear() && oDay.getMonth() == finishDate2.getMonth() && oDay.getDate() > finishDate2.getDate() )
)
{
disabledDayFlag = true;
aDayDiv.setAttribute("isJsDatePickDisabled",1);
}
}
您应该更新“JsDatePick.prototype.setConfiguration”:
JsDatePick.prototype.setConfiguration = function(aConf){
this.oConfiguration.isStripped = (aConf["isStripped"] != null) ? aConf["isStripped"] : false;
this.oConfiguration.useMode = (aConf["useMode"] != null) ? aConf["useMode"] : 1;
this.oConfiguration.selectedDate = (aConf["selectedDate"] != null) ? aConf["selectedDate"] : null;
this.oConfiguration.target = (aConf["target"] != null) ? aConf["target"] : null;
this.oConfiguration.yearsRange = (aConf["yearsRange"] != null) ? aConf["yearsRange"] : [1971,2100];
this.oConfiguration.limitToToday = (aConf["limitToToday"] != null) ? aConf["limitToToday"] : false;
this.oConfiguration.field = (aConf["field"] != null) ? aConf["field"] : false;
this.oConfiguration.cellColorScheme = (aConf["cellColorScheme"] != null) ? aConf["cellColorScheme"] : "ocean_blue";
this.oConfiguration.dateFormat = (aConf["dateFormat"] != null) ? aConf["dateFormat"] : "%m-%d-%Y";
this.oConfiguration.imgPath = (g_jsDatePickImagePath.length != null) ? g_jsDatePickImagePath : "img/";
this.oConfiguration.weekStartDay = (aConf["weekStartDay"] != null) ? aConf["weekStartDay"] : 1;
**this.oConfiguration.startDate = (aConf["startDate"] != null) ? aConf["startDate"] : '';
this.oConfiguration.finishDate = (aConf["finishDate"] != null) ? aConf["finishDate"] : '';**
....
}
创建DatePicker对象时:
g_globalObject = new JsDatePick({
useMode:1,
isStripped:true,
target:"div_calendar",
startDate:"05.01.2013",
finishDate:"05.31.2013"
});
答案 2 :(得分:0)
编辑:
读错了,你必须在你的选项中设置最小日期:
var options = {minDate:'03/18/2011',maxDate:today}
$("#datestart").datepicker(options);