简体   繁体   English

如何禁用jQuery Datepicker中的当前星期?

[英]How to disable current week in jquery datepicker?

I am trying to solve this problem. 我正在尝试解决这个问题。 Still I have done this, 我还是这样做了

 $(function() { $( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd', firstDay: 1, minDate:1 }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <input type="text" id="datepicker"> 

If you run this code you can see the calendar. 如果运行此代码,则可以看到日历。

I want to disable the full current week. 我想禁用当前的整个星期。 The available dates will start from next week. 可用日期将从下周开始。 As, Example, today is 18.07.2016 . 例如,今天是18.07.2016 So, if someone want to use this calendar then this full week become inactive. 因此,如果有人要使用此日历,则整整一周都将变为非活动状态。 Next available date will start from 24.07.2016 . 下一个可用日期将从24.07.2016月24日开始。

Thanks in advance for help. 在此先感谢您的帮助。

First find the number of day of week. 首先找到星期几。 And mindate will be counted accordingly and all the dates of current week will be disabled. 和注意将被相应地计算,并且本周的所有日期都将被禁用。 Please refer below code. 请参考下面的代码。

$(function() {
    var date = new Date();
    var dayNo = date.getDay();
    var mindate = (7-dayNo);

    $( "#datepicker" ).datepicker({
         dateFormat: 'yy-mm-dd', firstDay: 1,minDate: mindate
    });
});

Disabling the current week from Sunday to Saturday, you just need to set the firstDay as 0 (for Sunday) and use beforeShowDay which is used to take date as a parameter and return an array. 禁用从星期日到星期六的当前星期,您只需要将firstDay设置为0(对于星期日),并使用beforeShowDay (用于将日期作为参数并返回一个数组)即可。 For reference read Datepicker Option - beforeShowDay 供参考,请参阅Datepicker选项-beforeShowDay

Please check the snippet to enable all other dates in past and future both except disabling the current week dates. 请检查代码段以启用过去和将来的所有其他日期,除了禁用当前星期几。

Disable from Sunday to Saturday , use the below snippet 星期日到星期六禁用,请使用以下代码段

 $(function() { $("#datepicker").datepicker({ firstDay: 0, beforeShowDay: function (date) { var sunday = new Date(); sunday.setHours(0,0,0,0); sunday.setDate(sunday.getDate() - (sunday.getDay() || 0)); var saturday = new Date(sunday.getTime()); saturday.setDate(sunday.getDate() + 6); if (date >= sunday && date <= saturday) { return [false, '']; } else { return [true, '']; } } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <input type="text" id="datepicker"> 

And, also possibility to disable the whole week starting from Monday to Sunday 而且,还有可能从星期一到星期日禁用整个星期

 $(function() { $('#datepicker').datepicker({ firstDay: 1, beforeShowDay: function (date) { var monday = new Date(); monday.setHours(0,0,0,0); monday.setDate(monday.getDate() + 1 - (monday.getDay() || 7)); var sunday = new Date(monday); sunday.setDate(monday.getDate() + 6); if (date >= monday && date <= sunday) { return [false, '']; } else { return [true, '']; } } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <input type="text" id="datepicker"> 

Its A Simple Way TO Disable a Perticular Week 这是禁用一周的简单方法

<script>
 $(function(){
$('.bet_end').datepicker({              //ere .bet_end Is A Datepicker Class Name
    daysOfWeekDisabled: [0,6]   //Here Type Only Column Number To Disable Week 
     });
}); 
</script>

Click here To See Image (Sunday And Saturdat All Week Are Disable) 单击此处查看图像(周日和周六全周禁用)

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

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