tepicker中使用beforeShowDay来关闭一周中的某

tepicker中使用beforeShowDay来关闭一周中的某

本文介绍了在JQuery UI Datepicker中使用beforeShowDay来关闭一周中的某几天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要尝试的工作是在一周中的某些天关闭某个活动场所.每个场馆可能在不同的日子关闭.

what I am trying to do is grey out some days of the week for a venue for when it is closed. Each venue might be closed on different days.

我可以使用以下代码作为测试来关闭所有星期日:

I can use the following code as a test to close out all Sundays:

$('#bookingDatepicker').datepicker({
                minDate: 0,
                maxDate: '+3M',
                dateFormat: 'DD, d MM, yy',
                altField: '#actualDate',
                altFormat: 'yy-mm-dd',
                beforeShowDay:  closedDays
            });

function closedDays(date) {
  if (date.getDay() == 0){
  return [false,"","Venue Closed"];
  } else { return [true, ""];
}
}

但是,我可能不得不关闭一天以上,并且它们可能不会彼此相邻运行.在数据库中的代码中,我可以创建一个字符串,下面的示例显示了什么日子开放...

However I might have to close out more than one day and they might not run next to each other. In my code from the database I can create a string, examples below, which show what days are open...

1,2,3,4,5,6,0    //I would want to show no days closed
2,3,4,5,6        //I would want to show Sunday (0) and Monday (1) closed

我不确定该如何处理才能使上面的代码正常工作.我正在使用PHP创建字符串,因此可以根据需要使用该字符串进行操作.

I am not sure what to do with this though to get the code above to work. I am using PHP to create the string so can manipulate it using that if need be.

编辑

像往常一样,当您发布问题时,您会获得较小的突破!我已经开发了下面的代码,如果我在其中使用伪数据,它可以工作,但是我需要找到一种将字符串值包装在"中的方法.现在这给我带来了麻烦,如果我只使用var cloDays = [2,3,4,5],它将停止工作

As is usual when you post a question you get a minor breakthrough! I have developed the code below, it works if I use the dummy data in it, however I need find a way of wrapping my string values in "". That is now causing me trouble, if I just use var cloDays = [2,3,4,5] it ceases to work

var cloDays = ["2","3","4","5"];
 function closedDays(date){
 var sDate = date.getDay().toString();
 if ($.inArray(sDate, cloDays) == -1) return [false,"","Venue Closed"];
 else return [true, ""];
}

推荐答案

设法通过以下代码运行我的字符串来对其进行修复,基本上将其分解为PHP数组,然后使用JSON_Encode对其进行编码.似乎可以正常工作:

Managed to fix it by running my string through the code below, basically explodes it into a PHP array and then encodes it using JSON_Encode. Seems to work perfectly:

$cloDays = json_encode(explode(",", $cloDays));

这篇关于在JQuery UI Datepicker中使用beforeShowDay来关闭一周中的某几天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:15