[英]javascript disable event listener after first hit
How do I disable this event listener so that it only fires once? 如何禁用此事件侦听器以便它只触发一次?
document.getElementById('element').ontouchmove = function (e)
{
DISABLE HERE
do something that should only happen once
};
document.getElementById('element').ontouchmove = function (e) {
this.ontouchmove = null;
// Do something here.
};
Set a Boolean to false after first execution, which will be checked each time before the function runs: 首次执行后将布尔值设置为false,每次运行函数前都会检查它:
var doTouchEvent = true;
document.getElementById('element').ontouchmove = function (e)
{
if(doTouchEvent){
DISABLE HERE
do something that should only happen once
doTouchEvent = false;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.