【发布时间】:2017-09-23 06:34:10
【问题描述】:
有人可以帮忙检查一下为什么 removeHandler 不工作吗?以及如何让它发挥作用? 谢谢。
<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>
【问题讨论】:
标签: javascript