我使用了多个 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/