您可以將startDate和finishDate參數添加到jsDatePi CK。有一個「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"
});
我應該在哪裏使用這個 – shazia 2011-06-17 04:37:50
你想禁用日期選取器插件?或只是一些日期?我更新了我的代碼 – Ibu 2011-06-17 04:39:40
我正試圖在當前日期之前禁用日期。我已經添加腳本來加載日曆..在哪裏應該粘貼你寫的代碼。謝謝 – shazia 2011-06-17 04:47:13