在同一个元素上同时绑定单击和双击事件:
JavaScript
var timer = 0;
var delay = 200;
var prevent = false;
function singleClick(id)
{
clearTimeout(timer);
timer = setTimeout(function() {
if (!prevent) {copy(id);}
prevent = false;
},delay); //“200”单位是毫秒
}
function dbClick(id)
{
clearTimeout(timer);
prevent = true;
edit(id);
}
function copy(id)
{
var textInComment = document.getElementById(id).title;
var oInput = document.createElement(‘input‘);
oInput.value = textInComment;
document.body.appendChild(oInput);
oInput.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
oInput.className = ‘oInput‘;
oInput.style.display=‘none‘;
alert("Copy success, you can paste it!");
}
function edit(id)
{
var textInComment = document.getElementById(id).title;
var name=prompt("输入的内容","");
if (name!=null && name!="") {
alert("你输入的是" + name);
}
}
Html
原文:https://www.cnblogs.com/MasterMonkInTemple/p/10700589.html