繁体   English   中英

Magento日历:Datepicker问题将禁用今天之前的几天

[英]Magento calendar: Datepicker issue to disable days before today

我在前端自定义Magento日历时遇到问题:我想禁用今天之前的日期,该日期已经可以使用了,但是我无法选择实际月份中的日期。

但是,如果我单击下个月的任何日期并返回到本月,则可以选择日期!

这是我的代码:

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 
}); 

感谢帮助。

这样解决问题:

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

        };

希望它可以帮助某人:)

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;
                    }
                }

您可以禁用前几天以及下个月或当月的任何一天。

在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
                    });

要从日历中禁用前几天和即将到来的日子,例如:要禁用所有前一天和即将到来的周末,

<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 ,
});
//]]>

我希望此脚本对某人有帮助:

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM