日期:2014-05-16  浏览次数:20503 次

关于单击和双击的问题?
<body   onDblClick= "alert(2) "   onClick= "alert(1)   retrun   false ">
//我想单击时输出1双击时输出2

------解决方案--------------------
呵呵,不写不知道,写了一个才知道 LZ 的问题还挺有意思的,

L@_@K!

<!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>
<title> Single or Double Click </title>
</head>

<body>
<p> Click Me </p>
</body>
<script type= "text/javascript ">
<!--
// 点击间隔(单位:毫秒)
var numTimeOut = 300;
var numTimerID;
function singleClick()
{
alert( "Single click ");

// TODO: other things when single click.
// ...
}
document.body.onclick = function() {
if(numTimerID) window.clearTimeout(numTimerID);
numTimerID = window.setTimeout(singleClick, numTimeOut);
};
document.body.ondblclick = function() {
alert( "Double click ");
window.clearTimeout(numTimerID);

// TODO: other things when double click.
// ...
};
//-->
</script>
</html>