javascript:长按一下书签 [英] javascript: long click for a bookmarklet

查看:117
本文介绍了javascript:长按一下书签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要识别JavaScript书签小程序中的长时间点击。
所以,我不能使用jQuery,既不是onclick()事件也是类似的。是可能,以及如何?

I need to recognize a long click in a JavaScript bookmarklet. So, I cannot use jQuery, neither onclick() event and similar. Is it possible, and how?

推荐答案

onmousedown c $ c> setTimeout()。如果超时被允许过期,它将调用其函数来做任何你希望做的长时间点击。但是, onmouseup 您取消 setTimeout()(如果尚未到期)。

onmousedown, call setTimeout() for the duration of your long click. If the timeout is allowed to expire, it will call its function to do whatever you hoped to do on the long click. However, onmouseup you cancel the setTimeout() if it has not yet expired.

<script type='text/javascript'>
// t will hold the setTimeout id
// Click for 1 second to see the alert.
var t;
</script>

<button onmousedown='t=setTimeout(function(){alert("hi");}, 1000);' onmouseup='clearTimeout(t);'>Clickme</button>

这里是在jsfiddle的行动

这篇关于javascript:长按一下书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆