Jquery Bootstrap Datepicker:如何将限制设置为仅选择3个日期?
我正在使用Bootstrap Datepicker如何通过使用multidates选项设置限制以仅选择最多3个日期Jquery Bootstrap Datepicker:如何将限制设置为仅选择3个日期?,jquery,bootstrap-datepicker,Jquery,Bootstrap Datepicker,我正在使用Bootstrap Datepicker如何通过使用multidates选项设置限制以仅选择最多3个日期 var todayDate = moment().format('mm-dd-yyyy'); dp = $("#leaveDatePicker").datepicker({ format : "mm-dd-yyyy", multidate : true, inline : true,
var todayDate = moment().format('mm-dd-yyyy');
dp = $("#leaveDatePicker").datepicker({
format : "mm-dd-yyyy",
multidate : true,
inline : true,
todayHighlight : false,
daysOfWeekDisabled : [0],
startDate : 'today',
beforeShowDay : function(date){
var d = date;
var curr_month = d.getMonth() + 1; //Months are zero based
if(curr_month < 10)
curr_month = '0'+curr_month;
var formattedDate = curr_month + "-" + d.getDate() + "-" +d.getFullYear()
if ($.inArray(formattedDate, myActiveDates) != -1){
return {
classes: 'active'
};
}
return [true,""];
}
});
dp.data('datepicker').setDates($('input#datestring').val().split(','));
dp.on('changeDate', function (e){
$('input#datestring').val($(this).data('datepicker').getFormattedDate());
});
使用变量存储选定的日期数组 每当选择日期时,请检查日期选择器中数据的长度,如果数据长度超过3,则从存储的数组中进行重置并通知用户
var selectedDates = [];
dp.on('changeDate', function(e) {
if (e.dates.length < 4) {
// store current selections
selectedDates = e.dates
} else {
// reset dates if 4th selected
dp.data('datepicker').setDates(selectedDates);
alert('Can only select 3 dates')
}
});
使用变量存储选定的日期数组 每当选择日期时,请检查日期选择器中数据的长度,如果数据长度超过3,则从存储的数组中进行重置并通知用户
var selectedDates = [];
dp.on('changeDate', function(e) {
if (e.dates.length < 4) {
// store current selections
selectedDates = e.dates
} else {
// reset dates if 4th selected
dp.data('datepicker').setDates(selectedDates);
alert('Can only select 3 dates')
}
});
无需执行任何额外代码来设置多个日期选择的限制。只需将“多日期”选项与要设置为多日期限制的任何数字一起设置即可。请参见下面的示例,您最多只能选择三个日期 范例 $Txt_Date.datepicker{ 格式:“d-M-yyyy”, 内联:错, 朗:"嗯",, 步骤:5, 多日期:3, closeOnDateSelect:true };
无需执行任何额外代码来设置多个日期选择的限制。只需将“多日期”选项与要设置为多日期限制的任何数字一起设置即可。请参见下面的示例,您最多只能选择三个日期 范例 $Txt_Date.datepicker{ 格式:“d-M-yyyy”, 内联:错, 朗:"嗯",, 步骤:5, 多日期:3, closeOnDateSelect:true };
请把你的代码放在这里,我怎样才能把代码粘贴到这里?这是显示信息,评论太长,实际上我是新来的编辑您的问题,并添加代码请把您的一些代码我如何才能粘贴我的代码在这里?这是显示信息,评论太长,实际上我是新的编辑您的问题,并添加代码