2014-03-25 32 views
0

我有一個問題來自定義Magento日曆在前端: 我想禁用今天之前的日子,這已經有效,但我不能選擇實際月份中的日期。Magento日曆:Datepicker問題在今天之前禁用

但是,如果我點擊下個月的任何一個日期並返回到當前月份,那麼我可以選擇日期!!!!!!

這裏是我的代碼:

function disabledDate(date) { 
    var today = new Date(); 
    if(date <= today){ 
     return true; 
    } else { 
     return false; 
    } 
}; 
Calendar.setup({ 
    inputField : 'date', 
    ifFormat : '%e/%m/%Y', 
    button : 'date_from_trig', 
    align : 'Bl', 
    singleClick : true, 
    dateStatusFunc : disabledDate 
}); 

感謝您的幫助。

回答

3

問題解決了是這樣的:

 function disabledDate(date) { 
      var today = new Date(); 
      var dd = today.getDate(); 
      return date.getDate() < dd ;      

     }; 

希望它可以幫助別人:)

1

您可以禁用prevous天以及任何一天在未來或當前月份。

在disableFunc 0表示星期天禁用 1表示星期一 2表示星期二等。

以下是驗證碼。

function dateRange(date) { 
         var now = new Date(); 
         return (date.getTime() <= now.getTime()) 
         } 

        Calendar.setup({ 
          inputField : "aw_sarp_subscription_start", 
          ifFormat : "%m/%e/%Y", 
          dateStatusFunc : dateRange, 
          button  : "aw_sarp_subscription_start_trig", 
          align  : "Bl", 
          disableFunc : function(date){ 
           return date.getDay() === 0; 
           }, 
          singleClick : true 
        }); 
0

從日曆禁用以前的和即將到來的日子裏,EX:要禁用之前的所有日子和即將到來的週末,

<input type="text" class="datepicker" id="datepicker" name="shipment_date" /> 
<img id="_datepicker" src="<?php echo $this->getSkinUrl('images/img.gif');?>" alt="calendar" width="20" height="24" border="0"> 

//<![CDATA[ 

function disabledDate(date){ 
    var now= new Date(); 
    if(date.getFullYear() < now.getFullYear()) { return true; } 
    if(date.getFullYear() == now.getFullYear()) { if(date.getMonth() < now.getMonth()) { return true; } } 
    if(date.getMonth()  == now.getMonth())  { if(date.getDate()  < now.getDate()) { return true; } } 
    if (date.getDay() == 0 || date.getDay() == 6) { 
      return true; 
     } else { 
      return false; 
     } 
}; 

Calendar.setup({ 
    cont: "datepicker", 
    inputField : 'datepicker', 
    button : '_datepicker', 
    dateStatusFunc : disabledDate , 
}); 
//]]> 
1
disableFunc: function(date) { 
        var now= new Date(); 

       if(date.getFullYear()<now.getFullYear()) 
       { 
        return true; 
       } 
       if(date.getFullYear()==now.getFullYear()) 
       { 
        if(date.getMonth()<now.getMonth()) 
        { 
         return true; 
        } 
       } 
       if(date.getMonth()==now.getMonth()) 
       { 
        if(date.getDate()<now.getDate()) 
        { 
         return true; 
        } 
       } 
0

我希望有人該腳本將幫助:

<script type="text/javascript"> 
    Calendar.setup({ 
     inputField: 'your_input_field', 
     ifFormat: '<?php echo $this->getDateTimeFormat();?>', 
     button: 'you_button', 
     showsTime: true, 
     align: 'Bl', 
     singleClick: true, 
     disableFunc: function(date) { 
     //disables all dates before current date 
      var now = new Date(); 
      if(date.getFullYear() < now.getFullYear()){ 
       return true; 
      } 
      if(date.getFullYear() == now.getFullYear() && date.getMonth() < now.getMonth()){ 
       return true; 
      } 
      if(date.getMonth() == now.getMonth() && date.getDate() < now.getDate()){ 
       return true; 
      } 
     } 
    }); 
</script> 
相關問題