首页 > 解决方案 > 为什么 addEventListener 属性不起作用

问题描述

这是我的代码

const closeBtn = document.querySelector('.current button')

closeBtn.addEventListener('mouseover', e => {
  closeBtn.parentElement.style.display='none'
})
<div class="slide current">
            <div class="content">
                <button class="closeBtn">&times;</button>
                <h1>Orchidaceae</h1>
                <p>
                    There are between 22,000 and 26,000 species in 880 genera. They make up between 6–11% of all seed
                    plants. Orchids can be found in almost every country in the world except for Antarctica.
                </p>
            </div>
        </div>

你能检查一下有什么问题吗?

我正在尝试单击当前幻灯片上的关闭按钮以隐藏内容,但它没有显示任何错误,也没有任何线索!

标签: javascripthtmlcssaddeventlistener

解决方案


推荐阅读