2015-05-30 52 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