我有一个javascript函数,查看我的leave_start和leave_end datepickers然后它会计算出leave_start和leave_end之间的所有日期。哪个效果很好,但问题是可以说有人选择了4月10日这是一个星期五为leave_start然后为leave_end选择了4/13/15这是一个星期一,这将给我这样的所有日期4/10/15 ,4/11/15,2015年4月12日,4/13/15。我怎样才能让它向我展示周末不在2015年4月10日,2015年4月13日的日期?任何帮助将不胜感激!
这是我的app.js
$(document).ready(function() {
$('.customSub').click(function() {
var start = $('#leave_start').datepicker("getDate"),
end = $('#leave_end').datepicker("getDate"),
currentDate = new Date(start),
between = []
;
while (currentDate <= end) {
between.push(new Date(currentDate));
currentDate.setDate(currentDate.getDate() + 1);
}
var date_start = new Date();
var formated_dates = between.reduce(function(dates, the_date){
dates.push(date('m-d-Y' + ' ' , the_date));
return dates;
}, []);
// Figures out dates in between leave_end and leave_start and puts the value of it in gdates text_field
$('#gdates').val(formated_dates.join("\n"));
});
});
这是我的观点
.row-fluid
=simple_form_for @entry, :url => url_for(:controller => 'entry', :action => 'create'), :method => :post do |f|
%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
%th.lt Leave Start:
%td.lt= f.text_field :leave_start, :label => false, :id => 'leave_start', :input_html => {:value => ''}
%td.lt= f.error :leave_start, :class => 'er'
%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
%th.lt Leave End:
%td.lt= f.text_field :leave_end, :label => false, :id => 'leave_end', :input_html => {:value => ''}
%td.lt= f.error :leave_end, :class => 'er'
%td.lt= f.text_field :range_days, :label => false, :id => 'range_days', :input_html => {:value => ''}
%td.lt= f.text_field :full_range, :label => false, :id => 'gdates', :input_html => {:value => ''}
%table.table.table-bordered.table-striped{:style => 'table-layout:fixed; width:100% !important;'}
= f.button :submit, "Submit", :class => 'customSub', :style => 'margin-left:50px;'
答案 0 :(得分:1)
更改此代码块以适合...
while (currentDate <= end) {
if (currentDate.getDay() % 6 > 0) {
between.push(new Date(currentDate));
}
currentDate.setDate(currentDate.getDate() + 1);
}
它会检查星期几并忽略0或6天(星期日为0,星期六为6)。