0
如何禁用此事件偵聽器,以便它只觸發一次?javascript第一次打開後禁用事件偵聽器
document.getElementById('element').ontouchmove = function (e)
{
DISABLE HERE
do something that should only happen once
};
如何禁用此事件偵聽器,以便它只觸發一次?javascript第一次打開後禁用事件偵聽器
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.
};
設置一個布爾值,第一次執行後假,這將在每次函數運行前應檢查:
var doTouchEvent = true;
document.getElementById('element').ontouchmove = function (e)
{
if(doTouchEvent){
DISABLE HERE
do something that should only happen once
doTouchEvent = false;
}
};
是否設置爲null防止它再次燒製過的元素? – jamis0n
謝謝,這是我需要的。 – user984003
@ jamis0n,我只是簡單的替換了被調用的函數,一旦even被null觸發。 – rmobis