gpt4 book ai didi

javascript - 如何在 pickdate 调用时添加条件?

转载 作者:行者123 更新时间:2023-12-02 22:54:33 25 4
gpt4 key购买 nike

我的 html 是这样的:

<input id="appdate" type="text" class="required" placeholder="Select Date">

我的 JavaScript 是这样的:

...
$(document).ready(function () {
...
$('#appdate').change(function () {
console.log('when the retrieveSchedule function is called, this is not executed')
var date = $('#appdate').val();
...
});
});


appointment = function () {
function retrieveSchedule({ id, url }) {
...
$.ajax({
url: url,
type: 'GET',
data: '',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
...
var $input = $('#appdate').pickadate({
disable: _disableDate,
formatSubmit: 'yyyy-mm-dd',
min: someDate,
max: new Date((someDate.getFullYear() + 1), (someDate.getMonth() - 1), someDate.getDate()),
selectMonths: true,
selectYears: true,
close: 'Ok',
autoClose: false,
closeOnSelect: false, // Close upon selecting a date,
onClose: function () { $('.picker__input').removeClass('picker__input--target'); $('.picker').blur(); },
onRender: function () {
$('#appdate_root .picker__day-display').append('<div class="cal-notif"></div>');
var loadingcal = '<div class="cal-loading preloader-background">' +
'<div class="preloader-wrapper big active center">' +
'<div class="spinner-layer spinner-blue-only">' +
'<div class="circle-clipper left">' +
'<div class="circle"></div>' +
'</div>' +
'<div class="gap-patch">' +
'<div class="circle"></div>' +
'</div>' +
'<div class="circle-clipper right">' +
'<div class="circle"></div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
$('#appdate_root .picker__calendar-container').append(loadingcal);
}
});

// Use the picker object directly.
var picker = $input.pickadate('picker');
picker.clear();
if (picker.get('start')) {
var getdisable = picker.get('disable');
picker.set('enable', [1, 2, 3, 4, 5, 6, 7]);
picker.set('disable', _disableDate);
getdisable = picker.get('disable');
picker.render();

} else { console.log('false picker'); }
},
error: function (result) {
...
}
}).done(function () {
...
});
}
return { retrieveSchedule: retrieveSchedule }
}();

我不显示我的所有脚本。我只显示我遇到的问题的详细信息

上面的js文件运行时,首先会调用retrieveSchedule函数。如果ajax成功,它将创建一个pickdate并将其显示在id = appdate的输入文本中

我的问题是,当 pickdate 成功显示在 id = appdate 的输入文本中时,它还会在 $('#appdate').change(function({) 中运行此脚本。我想$('#appdate').change(function({) 里面的语句没有运行。所以它只在选择 pickdate 时运行。不显示 pickdate

如何制定条件?

最佳答案

创建这样的检查变量怎么样

var appdateCreated = false;

$('#appdate').change(function () {
if(appdateCreated) {
console.log('when the retrieveSchedule function is called, this is not executed')
} else {
appdateCreated = true
}
});

关于javascript - 如何在 pickdate 调用时添加条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58046894/

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