长按鼠标事件js

来源:互联网 发布:linux u盘启动盘 编辑:程序博客网 时间:2024/04/20 00:57

原文地址:http://www.chenfahui.cn/post/63.html


<!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=utf-8" />
<title>鼠标长按</title>
</head>
<body>
<input type="button" value="鼠标长按" class="lognPress" />
长按时间:<span class="time">0</span> 秒
<script type="text/javascript" src="http://www.chenfahui.cn/ziliao/js/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(function(){
    $(".lognPress").mousedown(function(){
        var i = 0;
        var _this = $(this);
        timer = setInterval(function(){
            i+=10;
            if(i >= 1000){
                i = 0;
                lognPress();
            }
        },10)
    }).mouseup(function(){clearTimeout(timer);});
})
var time = 0;
function lognPress(){
    time++;
    $(".time").html(time);
}
</script>
</html>

0 0
原创粉丝点击