gpt4 book ai didi

javascript - 跨浏览器addEventListener

转载 作者:行者123 更新时间:2023-11-30 15:36:43 24 4
gpt4 key购买 nike

我使用了多个 EventListener,但这个特定的在 IE 中不起作用:

document.querySelector('#assets').addEventListener('loaded', function () {
document.getElementById('startbutton').style.display = "inline";
});

document.querySelector('#assets').addEventListener('loaded', function () {
document.getElementById('loadingbutton').style.display = "none";
});

我想在 Assets 加载时显示一个按钮,然后在 Assets 加载后立即删除不显示的按钮。问题是 loadingbutton 没有被删除,所以样式没有被应用。这只发生在 Internet Explorer 中。我如何使用 attachEvent 编写它以使其工作?

按钮 html:

<button id="startbutton" class="my_popup_close button" onclick="playSound();setTimeout(showDiv, 2000);" name="answer" value="Show Div" style="display: none;">Ready</button>

<button class="buttonloading loader" id="loadingbutton">Loading<span class="loader__dot">.</span><span class="loader__dot">.</span><span class="loader__dot">.</span></button>

最佳答案

监听的元素是一样的,事件也是一样。您应该像这样组合回调:

document.querySelector('#assets').addEventListener('loaded', function (){
// display #startbutton and hide #loadingbutton
document.getElementById('startbutton').style.display = "inline";
document.getElementById('loadingbutton').style.display = "none";
});

关于javascript - 跨浏览器addEventListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41423592/

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