有人可以幫助檢查爲什麼removeHandler不工作?以及如何使其工作? 謝謝。爲什麼removeEventListener不工作
<body>
<button onclick="removeHandler()" id="myBtn">remove</button>
<p id="demo">hello</p>
<script>
document.getElementById("demo").addEventListener("click", myFunction("random: "));
function myFunction(t) {
var x = function(){
document.getElementById("demo").innerHTML = t+Math.random();
};
return x;
}
function removeHandler() {
document.getElementById("demo").removeEventListener("click", myFunction("random: "));
}
</script>
</body>
http://stackoverflow.com/questions/10444077/javascript-removeeventlistener-not-working或http://stackoverflow.com/questions/16651790/javascript-removeeventlistener-not -working-event-listener-remains或http://stackoverflow.com/questions/5825493/removeeventlistener-is-not-working – epascarello