首页 > 代码库 > javascript双击和单击事件共存

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 herealert("你单击了我");            }, 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=http://www.mamicode.com/"uploading.gif"><span>快捷上传</span></div></body></html> 

 

javascript双击和单击事件共存