我目前正在将HTML的模式附加到TD。我目前有一个显示附加模态的函数,但是,每次我单击模态时,它都会运行我单击TD时的代码(它将模态算作TD的一部分),因此不断显示相同的模式。
我尝试过:
document.addEventListener("show",function(){
$('td').off("click");
});
甚至:
$(this).off("click",`#${modalId}`);
JavaScript
$('td').on('click',function(e) {
$('td').removeclass("selectedDate");
$(this).addClass("selectedDate");
var n = $(this).find('.date').text(); //selects the date input for the cell.
let ordN = n + (n > 0 ? ['th','st','nd','rd'][(n > 3 && n < 21) || n % 10 > 3 ? 0 : n % 10] : '');
let modal= $('.modal').clone(true);
$(this).append(modal);
let modalId= `${months[currentMonth]}-${n}-${currentYear}`;
modal.attr('id',`${modalId}`);
$(this).find('#modalHeader').text(`${months[currentMonth]} ${ordN} ${currentYear}`);
$(this).find(`#${modalId}`).show();
document.addEventListener("show",function(){
$('td').off("click");
console.log('working')
});
console.log(this);
$(this).off("click",`#${modalId}`);
});
无论我在哪里看,我似乎都找不到解决此问题的方法...