我想在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);
$('.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>
答案 0 :(得分:0)