模拟长按事件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=GBK" /> <title>无标题文档</title> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <div id="mydiv" style="width:100px; height:100px; background:#ddd;">out</div> </body> </html> <script> /*设置一个长按的计时器,如果点击这个图层超过2秒则触发,mydiv里面的文字从out变in的动作*/ var timeout ; $("#mydiv").mousedown(function() { console.log(1) timeout = setTimeout(function() { $("#mydiv").text("in"); }, 2000); }); $("#mydiv").mouseup(function() { clearTimeout(timeout); $("#mydiv").text("out"); }); $("#mydiv").mouseout(function() { clearTimeout(timeout); $("#mydiv").text("out"); }); </script>