我需要识别 JavaScript 书签中的长按。
所以,我不能使用 jQuery,也不能使用 onclick() 事件和类似事件。这可能吗?如何实现?
onmousedown
, call setTimeout()
在长按期间。如果允许超时,它将调用其函数来执行您希望在长按时执行的任何操作。然而,onmouseup
你取消setTimeout()
如果尚未过期。
<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 中运行的 http://jsfiddle.net/hDRwN/5/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)