duanlu8613 2016-03-23 05:34
浏览 48

如何在php中按需启用和禁用特定日期?

I want to enable particular dates and disable it after completing task.I dont know how to start and what to do first.Please suggest me.

"02-03-2016","19-03-2016","23-03-2016",

  • 写回答

1条回答 默认 最新

  • dswe30290 2016-03-23 09:25
    关注

    It was a bit hard to understand your needs but I guess that you are using datepicker and you want to disable and renable some particular dates.

    You do it by using beforeShowDay while you instantiate your datepicker. Before to respond your question, let's start by reminding what the beforeShowDate does:

    A function that takes a date as a parameter and must return an array with:

    [0]: true/false indicating whether or not this date is selectable
    [1]: a CSS class name to add to the date's cell or "" for the default presentation
    [2]: an optional popup tooltip for this date
    

    The function is called for each day in the datepicker before it is displayed.

    So to disable a specific date you need to return [false] in the function beforeShowDate when you have in parameteter the date you want to disable and [true] if not. So I urge you to use a global variable dateDisabledArray where you put all the date you want to disable. So here's a small code where I disable these dates : "2016-03-11","2016-03-02" and "2016-03-24":

    var dateDisabledArray = ["2016-03-11","2016-03-02","2016-03-24"];
    $('input').datepicker({
        beforeShowDay: function(date){
            var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
            return [ dateDisabledArray.indexOf(string) == -1 ]
        }
    });
    

    Now if you want to renable the previous dates, you only have to do :

    dateDisabledArray = [];
    

    Here's a jsfiddle where I disable these dates on a click and renable them in the folowing click.

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)