gpt4 book ai didi

javascript - jQuery datepicker 禁用每周除一个日期外的所有日期

转载 作者:行者123 更新时间:2023-12-03 02:53:08 26 4
gpt4 key购买 nike

我想选择一个日期,假设我选择一个星期一,我只想只能在另一个日期选择器上选择星期一并禁用所有其他日期,换句话说,我想选择 7 天的间隔两个日期选择器之间。

我怎样才能实现这个目标?

我尝试过这个:

beforeShowDay: function(date) {
console.log('beforeShowDay');
var day = date.getDay();
return [day != day, ''];
},

但不确定它是否应该工作或者我应该将函数放置在哪个日期选择器中。

更新:

var curday = "";
var unavailableDays = [];
var dateselected = "";

function ViewDay(date) {
dmy = date.getDate() + "/" + (date.getMonth()+1) + "/" + date.getFullYear();
day = date.getDay();
if (date > dateselected) {
if ($.inArray(day, unavailableDays) == -1) {
return [false, "", "Unavailable"];
} else {
return [true, ""];
}
} else {
return [false, "", "Unavailable"];
}
}

$('#startdatesahasrara').datepicker({
dateFormat: 'dd/mm/yy',
minDate: 3,
onSelect: function(e) {

$('#enddatesahasrara').removeData("hasqtip");
$('#enddatesahasrara').removeAttr("data-hasqtip");
$('#enddatesahasrara').qtip("destroy", true);
$('#enddatesahasrara').removeAttr('title');

$('#enddatesahasrara').val('');
unavailableDays = [];
dateselected = new Date(e);
curday = new Date(e).getDay();
unavailableDays.push(curday);
console.log('trigger');
}
});

$("#enddatesahasrara").datepicker({
dateFormat: 'dd/mm/yy',
showAnim: "slideDown",
minDate: 0,
beforeShowDay: ViewDay
});

最佳答案

希望有帮助!

var curday = "";
var unavailableDays = [];
var dateselected = "";
$('.datepicker1').datepicker({
dateFormat: 'yy-mm-dd',
onSelect: function(dateText) {
$('.datepicker').val('');
unavailableDays = [];
dateselected = new Date(dateText);
curday = new Date(dateText).getDay();
unavailableDays.push(curday);
}
});

$(".datepicker").datepicker({
dateFormat: 'yy-mm-dd',
showAnim: "slideDown",
minDate: 0,
beforeShowDay: ViewDay //$.datepicker.noWeekends
});


function ViewDay(date) {
dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
day = date.getDay();
if (date > dateselected) {
if ($.inArray(day, unavailableDays) == -1) {
return [false, "", "Unavailable"];
} else {
return [true, ""];
}
} else {
return [false, "", "Unavailable"];
}
}
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js"></script>

<input type="text" class="datepicker1" />
<input type="text" class="datepicker" />

关于javascript - jQuery datepicker 禁用每周除一个日期外的所有日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47752252/

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