繁体   English   中英

第一次点击后,javascript禁用事件监听器

[英]javascript disable event listener after first hit

如何禁用此事件侦听器以便它只触发一次?

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.
};

首次执行后将布尔值设置为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM