首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在html/jQuery中注册两次单击

在html/jQuery中注册两次单击
EN

Stack Overflow用户
提问于 2020-06-04 15:06:24
回答 1查看 45关注 0票数 0

我用不同的ids打印了几次HTML-part代码(每个部分的${element.id}是不同的)。现在第一个子元素可以正常工作了,但是其他元素注册了两次单击(在一次单击之后,它的淡入和淡出)。我想删除此错误。我使用Laravel作为主要框架。对不起,我的英语:)提前谢谢!

代码语言:javascript
运行
复制
<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>
代码语言:javascript
运行
复制
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);
    }

})
EN

回答 1

Stack Overflow用户

发布于 2020-06-04 15:23:24

你应该改变:

代码语言:javascript
运行
复制
    if ( $("#drop_"+id).is(":visible") ) {
        $("#drop_"+id).fadeOut(1000);
    } else {
        $("#drop_"+id).fadeIn(1000);
    }

代码语言:javascript
运行
复制
    if ( $("#drop_"+id).is(":visible") ) {
        $("#drop_"+id).fadeOut(1000);
        return;
    }
        $("#drop_"+id).fadeIn(1000);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62188731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档