我希望它只显示一个月的日期,从minDate到maxDate。而且效果很好,但出于某种原因,它显示了两种观点。
这是JS:
var maxDate = new Date();
var minDate = $("#from").val();
var datePickerLimits= $("#from, #to").datetimepicker({
minDate: minDate,
maxDate: maxDate,
pickTime: false,
onSelect: function(selectedDate) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $(this).data("datetimepicker"),
date =
$.datetimepicker.parseDate(instance.settings.dateFormat ||
$.datetimepicker._defaults.dateFormat, selectedDate, instance.settings);
dates.not(this).datetimepicker("option", option, date);
}
});
滑轨:
= text_field_tag :from_js, l((params[:from].to_datetime or
@item.date), format: :american_no_time), class: 'form-control
input-sm datetimepicker', id: 'from'
= text_field_tag :to_js, l((params[:to].to_datetime or
@item.date_end), format: :american_no_time), class: 'form-control
input-sm datetimepicker', id: 'to'
这与rails一起使用但似乎在JS中发生,因为唯一被调用的是类datetimepicker。
答案 0 :(得分:1)
在日期选择器中添加 Startdate 和 EndDate
var today = new Date();
var lastDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);
在您的脚本中添加
var today = new Date(); //Get today's date
var lastDate = new Date(today.getFullYear(), today.getMonth() + 1, 0); //To get the last date of today's month
$("#datepicker").datepicker({
startDate: today,
endDate: lastDate
});

答案 1 :(得分:0)
这解决了问题。
var maxDate = new Date();
var minDate = $("#from").val();
$(function () {
$('#from').datetimepicker({
minDate: minDate,
maxDate: maxDate,
pickTime: false
});
$('#to').datetimepicker({
minDate: minDate,
maxDate: maxDate,
pickTime: false
});
});