我正在使用Materializecss。现在我正在创建一个酒店预订系统。我想要的是,当我在DateIn Datepicker上选择一个日期时,DateOut Datepicker分钟日期应该比选定日期提前1天。首先选择它正在工作。但是,当我尝试选择高于所选日期的检查日期时,dateout选取器的最短日期将不会更改。设置其他日期选择器的最短日期提前1天我的第一个日期选择器
$('#dp_ci').pickadate(
{
selectMonths: true, // Creates a dropdown to control month
min : new Date(),
clear: 'Clear',
close: 'Ok',
closeOnSelect: false // Close upon selecting a date,
});
$('#dp_ci').change(function(){
selected_ci_date ="";
selected_ci_date = $('#dp_ci').val();
if (selected_ci_date != null)
{
var cidate = new Date(selected_ci_date);
alert(cidate);
$("#dp_co").val("");
$("#dp_co").removeAttr("disabled");
min_codate = "";
min_codate = new Date();
min_codate.setDate(cidate.getDate()+1);
$('#dp_co').pickadate(
{
min : min_codate,
selectMonths: true, // Creates a dropdown to control month
clear: 'Clear',
close: 'Ok',
closeOnSelect: false // Close upon selecting a date,
});
$('#dp_co').change(function(){
if ($('#dp_co').val() != null)
{
var ci = new Date($('#dp_ci').val());
var co = new Date($('#dp_co').val());
var noOfdays = co.getDate() - ci.getDate() ;
alert(noOfdays);
}
});
}
})
编辑: 示例: 第一选择: dp_ci:2017年9月27日(选择的) dp_co(分钟):2017年9月28日(日期后面被禁用) dp_co:2017年9月28日(选择)
第二选择:(我将在dp_ci再次选择) dp_ci:2017年9月29日(选择) dp_co(分钟):2017年9月28日(还是这本来应该是9月29日)
更新:我找到了能够解决我的问题的答案。唯一的一件事是dp_co的最短日期不应该与dp_ci允许同一日期:任何解决方案?
$('#dp_ci').pickadate(
{
selectMonths: true, // Creates a dropdown to control month
today: 'Today',
clear: 'Clear',
close: 'Ok',
min: new Date()
});
var from_$input = $('#dp_ci').pickadate(),
from_picker = from_$input.pickadate('picker')
var to_$input = $('#dp_co').pickadate(),
to_picker = to_$input.pickadate('picker')
// Check if there’s a “from” or “to” date to start with.
if (from_picker.get('value'))
{
to_picker.set('min', from_picker.get('select'))
}
if (to_picker.get('value'))
{
from_picker.set('max', to_picker.get('select'))
}
// When something is selected, update the “from” and “to” limits.
from_picker.on('set', function(event)
{
if (event.select)
{
to_picker.set('min', from_picker.get('select'))
}
else if ('clear' in event)
{
to_picker.set('min', false)
}
})
to_picker.on('set', function(event)
{
if (event.select)
{
from_picker.set('max', to_picker.get('select'))
}
else if ('clear' in event)
{
from_picker.set('max', false)
}
})
来到这里的代码:
创建一个完整的工作的例子,说明了什么问题 – Dekel
@Dekel添加例如 –
这不是一个例子。例子是你可以运行和看到的东西,这正是我们在stackoverflow中有片段的原因。 – Dekel