如何禁用此事件侦听器以使其仅触发一次?
document.getElementById('element').ontouchmove = function (e)
{
DISABLE HERE
do something that should only happen 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.
};
首次执行后将布尔值设置为 false,每次在函数运行之前都会对其进行检查:
var doTouchEvent = true;
document.getElementById('element').ontouchmove = function (e)
{
if(doTouchEvent){
DISABLE HERE
do something that should only happen once
doTouchEvent = false;
}
};