[英]Will removeEventListener remove HTML attributes?
I haven't seen anyone else ask this question, and I'm curious if an attribute event handler will be removed via JavaScript removeEventListener
.我还没有看到其他人问过这个问题,我很好奇是否会通过 JavaScript
removeEventListener
删除属性事件处理程序。
<video id='myVideo' src='blah.mp4' onended='window.onMyVideoEnded'></video>
document.querySelector('#myVideo').removeEventListener('ended', window.onMyVideoEnded);
Will this code prevent the listener from being invoked, even though it's 'hardcoded' inline on the HTML element?这段代码是否会阻止调用侦听器,即使它是在 HTML 元素上内联的“硬编码”?
Nope, the event will still go.不,活动仍将继续。
window.clickFunction = function() { alert('Clicked!') } window.onload = function() { console.log('Loaded!') document.getElementById('button').removeEventListener('click', window.clickFunction) }
<button onclick = 'window.clickFunction()' id = 'button'>Test</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.