简体   繁体   English

按下按钮并按住Android PhoneGap中的操作

[英]Button press and hold for action in Android PhoneGap

I'm need to preform a specific action in my app if the user presses and holds a button for a few second, if the user removes his finger from the button before the delay runs out, then this action will be cancelled. 如果用户按下并按住按钮几秒钟,如果用户在延迟用完之前将手指从按钮上移开,我需要在我的应用程序中执行特定操作,然后此操作将被取消。 I use 'ontouchstart' event for the press. 我为媒体使用'ontouchstart'活动。

Is there any way i can achieve this using html and javascript? 有什么办法可以用html和javascript实现这个目的吗?

Thanks. 谢谢。

Here is a code snippets to achieve this particular requirement, 以下是实现此特定要求的代码段,

var pressTimer;
$("#btnClick").mouseup(function(){
  clearTimeout(pressTimer);
  return false;
});
$("#btnClick").mousedown(function(){
  pressTimer = window.setTimeout(function() { ... your code here ...},time_delay)
  return false; 
}); 

Search for keyup and keydown events in javascript 在javascript中搜索keyup和keydown事件

useful link: http://www.webmonkey.com/2010/02/javascript_events/#keydown 有用的链接: http//www.webmonkey.com/2010/02/javascript_events/#keydown

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM