press

jQuery中的100个技巧(译)

可紊 提交于 2019-12-06 05:27:43
1.当document文档就绪时执行JavaScript代码。   我们为什么使用jQuery库呢?原因之一就在于我们可以使jQuery代码在各种不同的浏览器和存在bug的浏览器上完美运行。 <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script> // Different ways to achieve the Document Ready event // With jQuery $(document).ready(function(){ /* ... */}); // Short jQuery $(function(){ /* ... */}); // Without jQuery (doesn't work in older IE versions) document.addEventListener('DOMContentLoaded',function(){ // Your code goes here }); // The Trickshot (works everywhere): r(function(){ alert('DOM Ready!'); }) function r(f){/in/.test(document.readyState)?setTimeout('r(

Long Press in JavaScript?

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is it possible to implement "long press" in JavaScript (or jQuery)? How? alt text http://androinica.com/wp-content/uploads/2009/11/longpress_options.png HTML Long press JavaScript $("a").mouseup(function(){ // Clear timeout return false; }).mousedown(function(){ // Set timeout return false; }); 回答1: There is no 'jQuery' magic, just JavaScript timers. var pressTimer; $("a").mouseup(function(){ clearTimeout(pressTimer); // Clear timeout return false; }).mousedown(function(){ // Set timeout pressTimer = window.setTimeout(function() { ... Your