如何获得点击次数 [英] How can I get the click count
本文介绍了如何获得点击次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在锚标记中,我想根据用户单击一次还是两次来调用两个不同的事件之一.但是,如果我实现ng-click
和ng-dblclick
,则两者都被激活.
In an anchor tag I would like call one of two different events based on if the user clicked once or twice. However if I implement ng-click
and ng-dblclick
, both are activated.
是否有任何方法可以根据点击次数路由到适当的侦听器?
Is there any way to route to the appropriate listener based on click count?
推荐答案
您可以结合使用ng-click和$ timeout来计算函数执行的次数.代码看起来像这样;
You can use a combination of ng-click and $timeout to count the number of times the function has been executed. the code could look like something like this;
<a ng-click="clicked()" />
$scope.clickCount = 0;
var timeoutHandler = null;
$scope.clicked = function()
{
if (timeoutHandler != null)
$timeout.cancel( timeoutHandler );
$scope.clickCount++;
timeoutHandler = $timeout(function()
{
//now you know the number of clicks.
//set the click count to zero for future clicks
$scope.clickCount = 0;
}, 500)
}
这篇关于如何获得点击次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文