简体   繁体   English

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

[英]How can I enable and disable specific date in php on demand?

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", “ 02-02-2016”,“ 19-03-2016”,“ 23-03-2016”,

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. 很难理解您的需求,但是我想您正在使用datepicker,并且您想要禁用和启用某些特定日期。

You do it by using beforeShowDay while you instantiate your datepicker. 您可以在实例化日期选择器时使用beforeShowDay完成此操作。 Before to respond your question, let's start by reminding what the beforeShowDate does: 在回答您的问题之前,让我们从提醒beforeShowDate做什么开始:

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. 因此,要禁止你需要返回的具体日期[false]的功能beforeShowDate当你parameteter必须要禁用的日期和[true]如果不是。 So I urge you to use a global variable dateDisabledArray where you put all the date you want to disable. 因此,我建议您使用全局变量dateDisabledArray ,在其中放置所有要禁用的日期。 So here's a small code where I disable these dates : "2016-03-11","2016-03-02" and "2016-03-24": 因此,这是一个禁用这些日期的小代码:“ 2016-03-11”,“ 2016-03-02”和“ 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. 这是一个jsfiddle ,我在单击时禁用这些日期,并在以下单击中启用它们。

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

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