简体   繁体   English

在Datepicker中禁用星期五和星期六

[英]Disable Friday and Saturday In Datepicker

I am trying to edit the beforeShowDay function in jquery.ui.datepicker. 我正在尝试在jquery.ui.datepicker中编辑beforeShowDay函数。 This is the original beforeShowDay lines in datepicker I'm trying to replace: 这是我要替换的datepicker中的原始 beforeShowDay行:

beforeShowDay: null, // Function that takes a date and returns an array with
        // [0] = true if selectable, false if not, [1] = custom CSS class 
        name(s) or '',
        // [2] = cell title (optional), e.g. $.datepicker.noWeekends

I have searched around trying to find the correct code to replace it with with no luck. 我四处搜寻,试图找到正确的代码来代替它,但没有运气。 I found this fiddle; 我发现了这个小提琴; disable 1 day in datepicker 在日期选择器中禁用1天

I have edited this fiddle and succeeded in disabling Friday and Saturday with the following code: 我已经编辑了这个小提琴,并使用以下代码成功禁用了星期五和星期六:

    $("#datepicker").datepicker({
    beforeShowDay: function(date) {
        return [date.getDay() == 0 || date.getDay() == 1 || date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ] ;
    }
});

However when I copy and paste this into jquery.ui.datepicker the calendar does not function and I'm getting console errors (Uncaught SyntaxError: Unexpected token). 但是,当我将其复制并粘贴到jquery.ui.datepicker中时,日历无法正常工作,并且出现控制台错误(未捕获的SyntaxError:意外的令牌)。

What I'm doing is replacing the original beforeShowDate with the following: 我正在用以下内容替换原始的 beforeShowDate:

beforeShowDay: function(date) { return [date.getDay() == 0 || date.getDay() == 1 || date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ] ; }

Can anyone advise what I'm doing wrong and how I can get this to function correctly? 谁能告诉我我做错了什么以及如何使它正常运行?

daysOfWeekDisabled daysOfWeekDisabled

Days of the week that should be disabled. 应该在星期几禁用。 Values are 0 (Sunday) to 6 (Saturday). 值是0(星期日)到6(星期六)。 Multiple values should be comma-separated. 多个值应以逗号分隔。 Example: disable weekends: '06' or '0,6' or [0,6]. 示例:禁用周末:“ 06”或“ 0,6”或[0,6]。

Use daysOfWeekDisabled for this 为此使用daysOfWeekDisabled

$('#datepicker').datepicker({
    daysOfWeekDisabled: [5,6]
});

Working fiddle 工作提琴

Edit 编辑

I did mistake in reading and post above answer about bootstarp datepicker. 我在阅读和发布上述有关bootstarp datepicker的答案时犯了错误。

For Jquery UI Datepicker try this 对于Jquery UI Datepicker,请尝试以下操作

beforeShowDay: function(d) {
   return [!(d.getDay()==0||d.getDay()==6)]
}

Working fiddle 工作提琴

You should not edit the jQuery UI plugin directly 您不应该直接编辑jQuery UI插件

If you really want then you have to paste this code replacing null. 如果确实需要,则必须粘贴此代码以替换null。 but it is not recommended . 但是不建议这样做

function(date) {
    var show = true;
    if(date.getDay()==6||date.getDay()==0) show=false;
    return [show];
},//don't forget comma after the function

Right way to do is to pass the function while configuring the jquery ui date-picker inside your own js file. 正确的方法是在自己的js文件中配置jQuery ui date-picker时传递函数。

$("#datepicker").datepicker({
    beforeShowDay: function(date) {
       var show = true;
       if(date.getDay()==6||date.getDay()==0) show=false
       return [show];
    }
});

You can try this, 你可以试试看

$("#datepicker").datepicker({
   beforeShowDay: function(date) {
    var day = date.getDay();
    return [(day != 5 && day != 6), ''];
  }
});

http://jsfiddle.net/nWAnz/238/ http://jsfiddle.net/nWAnz/238/

暂无
暂无

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

相关问题 使用带有联系表 7 的 jquery-ui-datepicker 禁用星期六 - disable saturday using jquery-ui-datepicker with contact form 7 在 angular 材料中禁用带有假期列表和工作日(周六和周日)的 mat-datepicker - Disable mat-datepicker with holidays list and weekdays(saturday & Sunday) in angular material 在角度4日期选择器中不包括星期六和星期日? - Excluding saturday and sunday in angular 4 datepicker? 获取上一个星期六的日期和下一个星期五的日期 - get previous saturday's date and next friday's 第一个和第三个星期六禁用全日历 - First and third saturday disable fullcalendar 想要显示星期六和星期日的连续星期五日期。 从星期一开始使用当前日期 - want to display consecutive Friday date for Saturday and Sunday. and from Monday is use current date 如果我在提示中输入'星期一',如何在控制台中显示'星期二','星期三','星期四','星期五','星期六','星期日'和'星期一' - how to display in the console ‘Tuesday’,’Wednesday’,’Thursday’,’Friday’,‘Saturday’ ,’Sunday’ and ‘Monday’ if I enter ‘Monday’ in the prompt 禁用公共假期,并在每个星期六在日历上选择特定时间范围 - Disable public holiday, and specific time range selected on calendar for every Saturday 在日期选择器中禁用日历 - disable calendar in datepicker 在 Datepicker 中禁用特定日期 - Disable Specific Dates in Datepicker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM