在jquery中禁用特定日期 [英] Disable specific dates in jquery

查看:124
本文介绍了在jquery中禁用特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这里找到的jquery日期选择器: http ://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerStartEnd.html ,允许用户选择开始和结束日期。



但是我想要禁用特定日期。



我试图实现这里找到的代码:stackoverflow.com/questions/501943/can-the-jquery-ui-讨论禁用国定假日的日期icker icker icker icker icker icker icker icker sat sat sat sat ida ida ida ida ida。。。。。。>>>>>>>>>>>>>>>

  $(function()
{


$(' datePicker({beforeShowDay:nationalDays})
// $(。selector)。datepicker({beforeShowDay:nationalDays})

var natDays = [
[1,26,'au]],[2,6,'nz'],[3,17,'ie'],
[4,27,'za'], 5,25,'ar'],[6,6,'se'],
[7,4,'us'],[8,17,'id'],[9,7 '],
[10,1,'cn'],[11,22,'lb'],[12,12,'ke']
];

function nationalDays(date){
for(i = 0; i< natDays.length; i ++){
if(date.getMonth()== natDays [i ] [0] - 1
&& date.getDate()== natDays [i] [1]){
return [false,natDays [i] [2] +'_day'] ;
}
}
return [true,''];
}

$('#start-date')bind(
'dpClosed',
函数(e,selectedDates)
{
var d = selectedDates [0];
if(d){
d = new Date(d);
$('#end-date')dpSetStartDate(d.addDays 1).asString());
}
}
);
$('#end-date')bind(
'dpClosed',
function(e,selectedDates)
{
var d = selectedDates [0] ;
if(d){
d = new Date(d);
$('#start-date')dpSetEndDate(d.addDays(-1).asString());
}
}
);

});

但这似乎不起作用。



我真的很感谢任何帮助解决这个问题!

解决方案

你似乎在两个不同的日期选择器之间混淆。您显示引用beforeShowDay的链接是 jQuery UI 日期戳器小部件的文档。但是您似乎正在使用我的日期选择器小部件



使用我的小部件,您需要使用 renderCallback 来禁用某些日期。这两个示例显示如何:



http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCustomCellRender.html
(禁用周末的弹出日历)



http:/ /www.kelvinluck.com/assets/jquery/datePicker/v2/demo/renderCalendarBankHolidays.html (另一个示例显示 renderCalendar renderCallback 显示英国银行假期 - datePicker 在幕后使用 renderCalendar ,以便您可以通过 renderCallback 以相同的方式。


I am using the jquery date picker found here: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerStartEnd.html that allows the user to pick a start and end date.

However I want to be able to disable specific dates.

I tried to implement the code found here: stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-be-made-to-disable-saturdays-and-sundays-and-holida that discusses disabling national holidays.

Here is my complete code:

$(function()
{


 $('.date-pick').datePicker({ beforeShowDay: nationalDays})
// $(".selector").datepicker({ beforeShowDay: nationalDays})   

 var natDays = [
   [1, 26, 'au'], [2, 6, 'nz'], [3, 17, 'ie'],
   [4, 27, 'za'], [5, 25, 'ar'], [6, 6, 'se'],
   [7, 4, 'us'], [8, 17, 'id'], [9, 7, 'br'],
   [10, 1, 'cn'], [11, 22, 'lb'], [12, 12, 'ke']
 ];

 function nationalDays(date) {
  for (i = 0; i < natDays.length; i++) {
    if (date.getMonth() == natDays[i][0] - 1
     && date.getDate() == natDays[i][1]) {
   return [false, natDays[i][2] + '_day'];
    }
  }
   return [true, ''];
 }

 $('#start-date').bind(
  'dpClosed',
  function(e, selectedDates)
  {
   var d = selectedDates[0];
   if (d) {
    d = new Date(d);
    $('#end-date').dpSetStartDate(d.addDays(1).asString());
   }
  }
 );
 $('#end-date').bind(
  'dpClosed',
  function(e, selectedDates)
  {
   var d = selectedDates[0];
   if (d) {
    d = new Date(d);
    $('#start-date').dpSetEndDate(d.addDays(-1).asString());
   }
  }
 );

});

But this does not seem to work.

I would really appreciate any assistance with solving this!

解决方案

You seem to be confused between two different date pickers. The link you show referring to "beforeShowDay" is documentation for the jQuery UI datepicker widget. But it appears you are using my date picker widget.

With my widget you need to use a renderCallback to allow you to disable certain dates. These two examples show how:

http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCustomCellRender.html (a popup calendar with weekends disabled)

http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/renderCalendarBankHolidays.html (another example showing renderCalendar with a renderCallback which shows UK bank holidays - datePicker uses renderCalendar behind the scenes so you can pass the renderCallback in in the same manner.

这篇关于在jquery中禁用特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆