长按鼠标事件js – Javascript – chenfahui

鼠标左键长按事件

:demo»

<p>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;<br>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;<br>&lt;head&gt;<br>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;<br>&lt;title&gt;鼠标长按&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;input type="button" value="鼠标长按" class="lognPress" /&gt;<br>长按时间:&lt;span class="time"&gt;0&lt;/span&gt; 秒<br>&lt;script type="text/javascript" src="http://www.chenfahui.cn/ziliao/js/jquery-1.4.1.min.js"&gt;&lt;/script&gt;<br>&lt;script type="text/javascript"&gt;<br>$(function(){<br>&nbsp;&nbsp;&nbsp; $(".lognPress").mousedown(function(){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var i = 0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var _this = $(this);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; timer = setInterval(function(){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i+=10;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(i &gt;= 1000){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; i = 0;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; lognPress();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; },10)<br>&nbsp;&nbsp;&nbsp; }).mouseup(function(){clearTimeout(timer);});<br>})<br>var time = 0;<br>function lognPress(){<br>&nbsp;&nbsp;&nbsp; time++;<br>&nbsp;&nbsp;&nbsp; $(".time").html(time);<br>}<br>&lt;/script&gt;<br>&lt;/html&gt;</p>

来源URL:http://www.chenfahui.cn/post/63.html