[英]How to stop onclick event?
I'd like to stop onclick
if I pressed it twice, but somehow it doesn't work...如果我按下两次,我想停止
onclick
,但不知何故它不起作用......
what am I doing wrong?我究竟做错了什么?
var timer
timer = document.querySelector("#home").onclick = function () {
setTimeout(function(){ alert("Expenses"); }, 1000);
}
console.log(timer);
document.querySelector("#home").setAttribute("ondblclick", "buildActionButton()");
function buildActionButton() {
timer.stopPropagation();
alert("ActionButton");
}
You need to create the event using 'addEventListener' instead of just changing its 'onclick' property.您需要使用“addEventListener”创建事件,而不仅仅是更改其“onclick”属性。 You can then use 'removeEventLister' to remove the 'onclick' event.
然后,您可以使用'removeEventLister'删除 'onclick' 事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.