详细描述请参加下面代码清单:
< HTML>
< HEAD>
< TITLE> javascript 实现单击和双击并存 < /TITLE>
< META NAME=" Generator" CONTENT=" EditPlus" >
< META NAME=" Keywords" CONTENT=" " >
< META NAME=" Description" CONTENT=" " >
< /HEAD>
< BODY>
< SCRIPT LANGUAGE=" JavaScript" >
< !--
var dcTime=250; // doubleclick time
var dcDelay=100; // no clicks after doubleclick
var dcAt=0; // time of doubleclick
var savEvent=null; // save Event for handling doClick().
var savEvtTime=0; // save time of click event.
var savTO=null; // handle of click setTimeOut
function showMe(txt) {
document.forms[0].elements[0].value += txt;
}
function handleWisely(which) {
switch (which) {
case " click" :
savEvent = which;
d = new Date();
savEvtTime = d.getTime();
savTO = setTimeout(" doClick(savEvent)" , dcTime);
break;
case " dblclick" :
doDoubleClick(which);
break;
default:
}
}
function doClick(which) {
if (savEvtTime - dcAt < = 0) {
return false;
}
showMe(" 单击" );
}
function doDoubleClick(which) {
var d = new Date();
dcAt = d.getTime();
if (savTO != null) {
savTO = null;
}
showMe(" 双击" );
}
//-->
< /SCRIPT>
< p>
< a href=" javascript:void(0)"
onclick=" handleWisely(event.type)"
ondblclick=" handleWisely(event.type)"
style=" color: blue; font-family: arial; cursor: hand" >
点击一下看看结果:
< /a>
< /p>
< form>
< table>
< tr>
< td valign=" top" >
事件模式: < textarea rows=" 4" cols=" 60" wrap=" soft" > < /textarea>
< /td>
< /tr>
< tr>
< td valign=" top" >
< input type=" Reset" >
< /td>
< /tr>
< /table>
< /form>
< /BODY>
< /HTML>