2015-05-30 53 views
1

我有一個代碼只能在onclick事件後執行。在移動設備上它很好,因爲我使用了touchstart和touchend。是否有類似於在電腦上使用觸摸屏的事件?onclick結束了嗎?

我的代碼目前類似於..

document.getElementById('trigger-box').addEventListener(function(e) { 
    // the event will be used later 
    // my code 
}); 

我試圖尋找答案互聯網可惜未能找到答案。因此,我在這裏發佈了我的問題。

+1

也許onmouseup? –

+0

@FabrizioMazzoni,的確是這樣的答案。 –

+0

我會說[Onmousedown](http://www.w3schools.com/jsref/event_onmousedown.asp)。 –

回答

1

按照評論:

document.getElementById('trigger-box').addEventListener("mouseup", function(e) { 
    // the event will be used later 
    // my code 
}); 
1

onmouseup發生之前執行click事件

<button onclick="console.log(1)" onmouseup="console.log(2)">test</button>

因此,我能想到的是手動完成時調用click事件唯一的解決方法

function myClick() 
 
{ 
 
    console.log('This is in click'); 
 
    afterClick(); 
 
} 
 

 
function afterClick() 
 
{ 
 
    console.log('This is after click'); 
 
}
<button onclick="myClick()" >test</button>

+0

嗯,它的作品,但我真的不推薦在HTML中嵌入點擊事件...並請使用'console.log()'爲調試目的 – KarelG

+0

@ KarelG,對不起,如果警報在哪裏討厭。更新我的答案以使用console.log。 – AmmarCSE