我希望当calender.html加载minRange并自动选择maxRange时
calender.html
<html>
<head>
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<link href="datepicker.min.css" rel="stylesheet" type="text/css">
<script src="datepicker.min.js"></script>
<!-- Include English language -->
<script src="datepicker.en.js"></script>
<script type="text/javascript">
var date = new Date();
var currentMonthStartDay = new Date(date.getUTCFullYear(), date.getUTCMonth(), 1);
var currentMonthLastDay = new Date(date.getUTCFullYear(), date.getUTCMonth() + 1, 0);
$('#my-element').data('datepicker').minRange = currentMonthStartDay;
$('#my-element').data('datepicker').maxRange = currentMonthLastDay;
</script>
</head>
<body>
<!-- <input type='text' class="datepicker-here" data-position="right top" /> -->
<div class="datepicker-here" id='my-element' data-language='en' data-range="false"></div>
</body>
</html>
我无法设置minRange和maxRange
答案 0 :(得分:1)
在我的情况下,我限制了日期选择,以便用户只能看到两天之间的日期:今天和即将到来的一天(分配10天后=它是一个变量,您可以根据需要更改它) assumed that today is 07/27/2017 thus 05/08/2017 would be 10days later~yay
第一: 我的代码:
var myDate=new Date() ;
// Variable Declare=today
var spanDay = myDate.getDate();
myDate.setDate(spanDay + 10);
//code above means you have assigned 10 days after myDate
然后:
//in datepicker plugin
var $cells = $('#custom-cells');
$cells.data('datepicker');
$cells.datepicker({
todayButton: new Date(),
minDate: new Date(),
maxDate:myDate,
onRenderCell: function (date, cellType) {
if (cellType == 'day') {
var day = date.getDay(),
isDisabled = disabledDays.indexOf(day) != -1;
return {
disabled: isDisabled
}
}
}
});
答案 1 :(得分:0)
试试这个
$('#minMaxExample').datepicker({
language: 'en',
minDate: new Date() // Now can select only dates, which goes after today
})
答案 2 :(得分:0)
您可以使用air datepicker的方法selectDate(),如下所示:
var datepicker = $('#my-elem').datepicker().data('datepicker');
datepicker.selectDate(startDate);
datepicker.selectDate(endDate);
确保您的startDate和endDate是javascript日期,如果不是,请使用
new Date(startDate)