MaterialiseCSS禁用特定日期

时间:2018-05-16 15:24:58

标签: date datepicker materialize

我正在尝试禁用MaterialiseCSS中的周末(周六和周日)和一些日期(如'2018-05-11','2018-05-21','2018-05-24'等) datepicker,但我想每年禁用这些日期。我可以用

禁用日期和日期
$('.datepicker').pickadate({
       disable: [
            1, 7, new Date(2018,5,11), {from: [2018,5,11], to: [2018,5,22]}, {from: [2018,8,5], to: [2018,8,17]}
       ]
});

所以我想知道是否有办法让它每年重复一次。

2 个答案:

答案 0 :(得分:0)

materializecss pickers

您可以在初始化datepicker时自定义使用disableDayFn选项禁用的天数。这个CodePen显示了disableDayFn选项的示例,该选项用于禁用每年的5月11日,21日和24日的周末。

答案 1 :(得分:0)

$('.disablePast').pickadate({
        selectMonths: true, // Creates a dropdown to control month
        selectYears: 105, // Creates a dropdown of 15 years to control year,
        today: 'Today',
        clear: 'Clear',
        close: 'Ok',
        format : 'dd/mm/yyyy',
        closeOnSelect: true,
        min : true
    });
    $('.datepicker').pickadate({
        selectMonths: true, // Creates a dropdown to control month
        selectYears: 105, // Creates a dropdown of 15 years to control year,
        today: 'Today',
        clear: 'Clear',
        close: 'Ok',
        format : 'dd/mm/yyyy',
        closeOnSelect: true,

        onSet: function(context) {
            var id = this.$node[0].id;
            var d = new Date(context.select);
            var dd = d.getDate();
            var mm = d.getMonth()+1; //January is 0!

            var yyyy = '';
            yyyy = new Date().getFullYear();
            year1=yyyy;
            month1=mm;
            if(dd<10){
                dd='0'+dd;
            } 
            if(mm<10){
                mm='0'+mm;
            } 
            var df = mm+'/'+dd+'/'+yyyy;
            var msec = Date.parse(df);
            var d1 = new Date();
            var d2 = new Date(msec);
            var timeDiff = d2.getTime() - d1.getTime();
            var DaysDiff = timeDiff / (1000 * 3600 * 24);
            var dff = '';
            var dft = '';
            if(DaysDiff >= 0){
                dff = dd+'/'+mm+'/'+yyyy;
            } else{
                yyyy = yyyy + 1;
                dff = dd+'/'+mm+'/'+yyyy;
            }




             if(month1==1) 
             {
                year1 = year1 - 1;


                month1 = 12;

            }
            else if(month1<=10)
            {
                month1=month1-1;
                month1='0'+month1;
            }
            else
            {
                month1=month1-1;
            }
            dft = dd+'/'+month1+'/'+year1;








            /*if(df > 0){
                dft = dd+'/'+mm+'/'+yyyy;
            }
            // if(mm = 01) {
            //     mm = 12;
            //     yyyy = yyyy - 1;
            //     dft = dd+'/'+mm+'/'+yyyy;
            // }
             else{
                yyyy = yyyy + 1;
                mm = mm - 1;
                dft = dd+'/'+mm+'/'+yyyy;
            }*/
             console.log(dft);
            if(id == 'dob')
                $('#dob_rem_on').val(dff);
            if(id == 'aniv_date')
                $('#aniv_rem_on').val(dff);
            if(id == 'passport_ren')
                $('#pass_rem_on').val(dft);
            if(id == 'insurance_ren')
                $('#insurance_rem_on').val(dft);
            if(id == 'life_insurance_ren')
                $('#life_insurance_rem_on').val(dft);
            Materialize.updateTextFields();
        }    
});