我用不同的ids打印了几次HTML-part代码(每个部分的${element.id}
是不同的)。现在第一个子元素可以正常工作了,但是其他元素注册了两次单击(在一次单击之后,它的淡入和淡出)。我想删除此错误。我使用Laravel作为主要框架。对不起,我的英语:)提前谢谢!
<div class="notification warning closeable" id="checkbox-area">
<input type="checkbox" name="blocks[]" class="form-check-input" id="element${element.id}" value="${element.url}" checked>
<label class="form-check-label" for="element${element.id}">${element.name}
<img src="${window.location.origin}/${element.thumbnail}" id="original" class="imgBlocks">
</label>
<button class="dropbtn" data-id="${element.id}" type="button">...</button>
</div>
<div class="drop-down" id="drop_${element.id}">
<div id="text-generation" class="drop-down-text">
</div>
<button type="button" id="btn-text-updater">new text</button>
</div>
const textGen = document.getElementById('text-generation');
const btnUpdateTextGen = document.getElementById('btn-text-updater');
let countTextRefresh = 0;
$(dotsBtn).click(function (e) {
e.preventDefault();
let id = $(this).attr("data-id")
if ( $("#drop_"+id).is(":visible") ) {
$("#drop_"+id).fadeOut(1000);
} else {
$("#drop_"+id).fadeIn(1000);
}
})
发布于 2020-06-04 15:23:24
你应该改变:
if ( $("#drop_"+id).is(":visible") ) {
$("#drop_"+id).fadeOut(1000);
} else {
$("#drop_"+id).fadeIn(1000);
}
至
if ( $("#drop_"+id).is(":visible") ) {
$("#drop_"+id).fadeOut(1000);
return;
}
$("#drop_"+id).fadeIn(1000);
https://stackoverflow.com/questions/62188731
复制相似问题