我的代码中有一个日期选择器,当我在所有请求完成之前打开日期选择器时,它会在我的日期选择器下拉列表中添加一个内联日期选择器,这是我的代码
<div class="hand-date-picker mr-3">
@Html.TextBox("InHandDate", "", new { @class = "datepicker", @group = "inhanddate", @data_date_format = HelperMethods.GetDateFormat(), @data_test_selector = "txtInHandDate" }) <span class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar"></span>
</div>
并在课堂上初始化
$("#InHandDate").datepicker({
//@ts-ignore
daysOfWeekDisabled: '0,6'
});
$("#InHandDate").datepicker('setDaysOfWeekDisabled', [0, 6])
并在脚本元素中
$(document).ready(function () {
let minDate;
if ($("input[class='PickUpShipping']").is(":checked")){
$(".CashOnPickup").show();
$("#warehouses-select").css("display", "block");
minDate = '@(HelperMethods.GetDateTime())';
} else {
$(".CashOnPickup").hide();
$("#warehouses-select").css("display", "none");
minDate = '@(HelperMethods.GetDateTime().AddDays(1))';
}
$("#InHandDate").datepicker('setStartDate', new Date(minDate))
});
$("input[name='ShippingOptions']").on("click", function (ev) {
let minDate;
if ($(this).data('shippingcode') === 'Pickup') {
$(".CashOnPickup").show();
$("#warehouses-select").css("display", "block");
minDate = '@(HelperMethods.GetDateTime())';
} else {
$(".CashOnPickup").hide();
$(".CashOnPickup input").prop('checked', false);
$("#warehouses-select").css("display", "none");
minDate = '@(HelperMethods.GetDateTime().AddDays(1))';
}
$("#InHandDate").datepicker('setStartDate', new Date(minDate))
});
$("input[name='ShippingOptions']").on("change", function (ev) {
$("#InHandDate").datepicker('setDate', "");
});
我尝试用多种方式来阻止它。但到目前为止还没有运气
显然这是因为没有设置 minDate 属性。添加'@minDate =“”' HTML 解决了问题