gpt4 book ai didi

javascript - 基于周限制日历

转载 作者:行者123 更新时间:2023-12-03 06:40:57 26 4
gpt4 key购买 nike

我使用日历。我想在用户选择日期时限制日历,那么日期选择必须是每周基本我该怎么做?天数可能是随机的,例如周一到周日或周二到周一等..必须是 7 天

代码

     <script type="text/javascript">

$(function() {
var currentYear = (new Date).getFullYear();
var currentMonth = (new Date).getMonth();
var currentDay = (new Date).getDate();

$("#fromdate").datepicker({
minDate: new Date((currentYear - 1), 12, 1),
dateFormat: 'dd/mm/yy',
maxDate: new Date(currentYear, currentMonth, currentDay)
});
$("#todate").datepicker({
minDate: new Date((currentYear - 1), 12, 1),
dateFormat: 'dd/mm/yy',
maxDate: new Date(currentYear, currentMonth, currentDay)
});
});
</script>

HTML

 <asp:Label ID="Label1" runat="server" Text="From Date"></asp:Label>

<input ID="fromdate" runat="server" ClientIDMode="static" />

<asp:Label ID="Label2" runat="server" Text="To Date"></asp:Label>

<input ID="todate" runat="server" ClientIDMode="static" />

最佳答案

试试这个,

$(function() {
var currentYear = (new Date).getFullYear();
$('#fromdate').datepicker({
minDate: 0,
dateFormat: 'dd/mm/yy',
maxDate: new Date((currentYear + 1), 12, 1),
onSelect: function(selectedDate) {

// Start Date
var startDate = $(this).datepicker('getDate');
$('#todate').datepicker('option', 'minDate', startDate);
$('#todate').datepicker('setDate', startDate);

// End Date
var enddate = $(this).datepicker('getDate');
enddate.setDate(enddate.getDate()+ 6);
$('#todate').datepicker('option', 'maxDate', enddate);
}});

$('#todate').datepicker({
minDate: 0,
dateFormat: 'dd/mm/yy',
maxDate: '+6'
});

});

关于javascript - 基于周限制日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37962349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com