将工作日添加到jquery中的新日期 [英] Add business days to the new date in jquery
本文介绍了将工作日添加到jquery中的新日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在1个工作日内添加新的日期。例如,如果用户选择任何星期五,则应在第二个字段中显示星期一的日期。以下是代码:
Jquery:
< script type ='text / javascript'>
//<![CDATA [
$(function(){
$('。one')。datepicker({
onSelect:function(date ){
var date2 = $('。one')。datepicker('getDate');
console.log(date2.getUTCDay());
if(date2.getUTCDay() == 4)
date2.setDate(date2.getDate()+ 3);
else
date2.setDate(date2.getDate()+1);
$(' 。二 ')日期选择器(' 的setDate 'DATE2);
},
beforeShowDay:$ .datepicker.noWeekends
})
$(' 二)日期选择器。 ({beforeShowDay:$ .datepicker.noWeekends})
});
$(document).ready(function(){
var currentItem = 1;
$(。datepicker)。datepicker();
$('#addnew' ).click(function(){
currentItem ++;
$('#items')。val(currentItem);
var strToAdd ='< tr>< td style = ><输入类型= 文本 名称= 任务 '+ CURRENTITEM +' ID = 任务 '+ CURRENTITEM +' 值= />< / TD>< TD风格= >< ; input type =textname =Description'+ currentItem +'id =Description'+ currentItem +'value =/>< / td>< td style =width:160px;> <输入类型= 文本 类= 一个日期选择器 名称= Internal_Deadline '+ CURRENTITEM +' ID = Internal_Deadline '+ CURRENTITEM +'/>< / TD>< TD风格= >< ; INPUT TYPE = 文本 类= 2个日期选择器 名称= Client_Deadline '+ CURRENTITEM +' ID = Client_Deadline '+ CURRENTITEM +'/>< / TD>< TD风格= >< input type =textclass =datepickername =Actual_Deadline'+ currentItem +'id =Actual_Deadline'+ currentItem +'/>&l t; / td>< td style =width:83px;>< / td>< / tr>';
$('#data')。append(strToAdd);
$(。datepicker)。datepicker();
});
});
//]]>
< / script>
HTML:
< TABLE id =dataclass =ddstyle =>
< TR>
< td style =>< input type =textname =task1id =task1value =/>< / td>< td style = >< input type =textname =Description1id =Description1value =/>< / td>< td style =width:160px;>< input type = 文本 类= 一个日期选择器 名称= Internal_Deadline1 ID = Internal_Deadline1 值= />< / TD>< TD><输入类型= 文本 类= 2个日期选择器 的名称= Client_Deadline1 ID = Client_Deadline1 值= />< / TD>< TD风格= ><输入类型= 文本 类= 日期选择器 名称= Actual_Deadline1 ID = Actual_Deadline1value =/>< / td>< td style =width:83px;>< / td>< / tr>
< input type =hiddenid =itemsname =itemsvalue =1/>
< / TABLE>
< / form>
解决方案
您需要在您的initilization中添加以下代码:
beforeShowDay:$ .datepicker.noWeekends
工作小提琴: http://jsfiddle.net/47SeR/4/
I would like to add the new date with 1 business day. For example if user select any Friday, it should display Monday's date in the second field. Below is the code:
Jquery:
<script type='text/javascript'>
//<![CDATA[
$(function () {
$('.one').datepicker({
onSelect: function(date){
var date2 = $('.one').datepicker('getDate');
console.log(date2.getUTCDay());
if(date2.getUTCDay() == 4)
date2.setDate(date2.getDate()+3);
else
date2.setDate(date2.getDate()+1);
$('.two').datepicker('setDate', date2);
},
beforeShowDay: $.datepicker.noWeekends
})
$('.two').datepicker({beforeShowDay: $.datepicker.noWeekends})
});
$(document).ready(function() {
var currentItem = 1;
$(".datepicker").datepicker();
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<tr><td style=""><input type="text" name="task'+currentItem+'" id="task'+currentItem+'" value="" /></td><td style=""><input type="text" name="Description'+currentItem+'" id="Description'+currentItem+'" value="" /></td><td style="width: 160px;"><input type="text" class="one datepicker" name="Internal_Deadline'+currentItem+'" id="Internal_Deadline'+currentItem+'" /></td><td style=""><input type="text" class="two datepicker" name="Client_Deadline'+currentItem+'" id="Client_Deadline'+currentItem+'" /></td><td style=""><input type="text" class="datepicker" name="Actual_Deadline'+currentItem+'" id="Actual_Deadline'+currentItem+'" /></td><td style="width:83px;"></td></tr>';
$('#data').append(strToAdd);
$(".datepicker").datepicker();
});
});
//]]>
</script>
HTML:
<TABLE id="data" class="dd" style="">
<TR>
<td style=""><input type="text" name="task1" id="task1" value="" /></td><td style=""><input type="text" name="Description1" id="Description1" value="" /></td><td style="width: 160px;"><input type="text" class="one datepicker" name="Internal_Deadline1" id="Internal_Deadline1" value="" /></td><td><input type="text" class="two datepicker" name="Client_Deadline1" id="Client_Deadline1" value="" /></td><td style=""><input type="text" class="datepicker" name="Actual_Deadline1" id="Actual_Deadline1" value="" /></td><td style="width: 83px;"></td></tr>
<input type="hidden" id="items" name="items" value="1" />
</TABLE>
</form>
解决方案
You need to add the following code in your initilization:
beforeShowDay: $.datepicker.noWeekends
Working Fiddle: http://jsfiddle.net/47SeR/4/
这篇关于将工作日添加到jquery中的新日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文