3

我正在做一个酒店预订项目,其中我需要提供两个输入字段作为到达日期和出发日期,在到达日期我已经显示今天的日期为默认值,用户可以点击并可以更改日期。所以有到达日期没有问题。但问题出发日期,我为出发日期做了同样的事情,但它没有工作,没有显示在出发日期内。我需要在这里做出什么样的改变。如何使用日期选择器将明天的日期设置为默认日期?

的代码如下,

$(document).ready(function() { 
 
    var date = new Date(); 
 
    var today = new Date(date.getFullYear(), date.getMonth(), date.getDate()); 
 
    var tomorrow = new Date(date.getFullYear(), date.getMonth(), date.getDate()); 
 
    var end = new Date(date.getFullYear(), date.getMonth(), date.getDate()); 
 

 
    $('#datepicker1').datepicker({ 
 
format: "mm/dd/yyyy", 
 
todayHighlight: true, 
 
startDate: today, 
 
endDate: end, 
 
autoclose: true 
 
    }); 
 
    $('#datepicker2').datepicker({ 
 
format: "mm/dd/yyyy", 
 
todayHighlight: true, 
 
startDate: tomorrow, 
 
endDate: end, 
 
autoclose: true, 
 
minDate : "+1" 
 
    }); 
 

 
}); 
 
$('#datepicker1').datepicker('setDate', '0'); 
 
$('#datepicker2').datepicker('setDate', '1');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" /> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.1/js/bootstrap-datepicker.js"></script> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.1/css/bootstrap-datepicker.min.css" /> 
 

 
<input id="datepicker1" type="text"> 
 

 
<input id="datepicker2" type="text">

,也是我需要掩饰以前的日期,即,我需要设置从今天才有效日期和日期的所有其余高达昨天需要处于非活动状态。

请给我这两个解决方案来解决我的问题。

+0

对于你的第一个问题,这是一个重复https://stackoverflow.com/questions/6831679/jquery-ui-date-picker-set-tomorrows-date-as-default – pokeybit

+0

可能重复的[jquery ui datepicker设置明天约会默认](https://stackoverflow.com/questions/6831679/jquery-ui-date-picker-set-tomorrows-date-as-default) – pokeybit

回答

3

在这里,你去与解决方案https://jsfiddle.net/7wdw0fr6/1/

$(document).ready(function() { 
 
    var date = new Date(); 
 
    var today = new Date(date.getFullYear(), date.getMonth(), date.getDate()); 
 
    var tomorrow = new Date(date.getFullYear(), date.getMonth(), (date.getDate() + 1)); 
 
    var end = new Date(date.getFullYear(), date.getMonth(), (date.getDate() + 1)); 
 
\t 
 
    $('#datepicker1').datepicker({ 
 
    format: "mm/dd/yyyy", 
 
    todayHighlight: true, 
 
    startDate: today, 
 
    endDate: end, 
 
    autoclose: true 
 
    }); 
 
    $('#datepicker2').datepicker({ 
 
    format: "mm/dd/yyyy", 
 
    startDate: tomorrow, 
 
    endDate: end, 
 
    autoclose: true 
 
    }); 
 
    
 
    $('#datepicker1').datepicker('setDate', '0'); 
 
    var datepicker2 = (date.getMonth() + 1) + '/' + (date.getDate() + 1) + '/' + date.getFullYear(); 
 

 
    $('#datepicker2').datepicker('setDate', datepicker2); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" /> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.1/js/bootstrap-datepicker.js"></script> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.1/css/bootstrap-datepicker.min.css" /> 
 

 
<input id="datepicker1" type="text"/> 
 

 
<input id="datepicker2" type="text"/ >

错误 $( '#DATEPICKER1')日期选择器( '的setDate', '1')。

应该是 $('#datepicker2')。datepicker('setDate','1');

+0

但在第二个输入框中,我需要显示明天的日期作为活动.. –

+0

让我更新代码并在一段时间内分享小提琴。 – Shiladitya

+0

我已更新代码,看看并让我知道... – Shiladitya

相关问题