javascript双击和单击事件共存

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
        .quick{
width: 105px;
height: 36px;
background-image: url("ic_cloud_upload_white_24dp.png");
background-repeat: no-repeat;
background-color: black;
cursor:pointer;
        }
        .quick img {
visibility: visible;
position: absolute;
        }

        .quick span {
font-size: 14px;
/*padding-top: 12px;*/
float: right;
color: white;
line-height: 40px;
        }
        //这里为双击文字时,背景色不让其高亮
body{-moz-user-select:none;}//火狐
/*<body onselectstart="return false">*/其他浏览器
</style>
<script type="text/javascript">
var clickTimer = null;
function _click(){
if(clickTimer) {
window.clearTimeout(clickTimer);
clickTimer = null;
            }

clickTimer = window.setTimeout(function(){
// your click process code here
alert("你单击了我");
            }, 300);
        }
function _dblclick(){
if(clickTimer) {
window.clearTimeout(clickTimer);
clickTimer = null;
            }
alert("你双击了我");
        }

</script>
</head>
<body >
<div onselectstart="return false" onclick="_click();" ondblclick="_dblclick();" class="quick"><img src="uploading.gif"><span>快捷上传</span></div>
</body>
</html>
 

 

posted @ 2016-10-12 18:41  神经质攻城狮马磊  阅读(380)  评论(0编辑  收藏  举报