如何在jsdatepicker当前日期之前禁用日期

问题描述:

我正在使用jsdatepicker来显示日历。如何在jsdatepicker当前日期之前禁用日期

http://javascriptcalendar.org/javascript-date-picker.php

function initialize() 

{ 
     new JsDatePick({ 
        useMode:2, 
      limitToToday :false, 
      target:"deadlinedate", 
      dateFormat:"%d-%m-%Y" 
      }); 
} 

有什么办法当前日期之前禁用所有日期。 任何帮助,将不胜感激。

感谢

编辑:

读错,你必须设置最小日期为您的选择:

var options = {minDate:'03/18/2011',maxDate:today} 
$("#datestart").datepicker(options); 
+0

我应该在哪里使用这个 – shazia 2011-06-17 04:37:50

+1

你想禁用日期选取器插件?或只是一些日期?我更新了我的代码 – Ibu 2011-06-17 04:39:40

+0

我正试图在当前日期之前禁用日期。我已经添加脚本来加载日历..在哪里应该粘贴你写的代码。谢谢 – shazia 2011-06-17 04:47:13

下载完整版而不是分之一,并改变JsDatePick.prototype.isAvailable函数> for < in all 3 ifs

您可以将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" 
    });