首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

onmousedown小弟我 觉得这个很无语

2012-03-31 
onmousedown我 觉得这个很无语input nametest idtest typebutton onmousedownmouseDown()val

onmousedown我 觉得这个很无语
<input name="test" id="test" type="button" onmousedown="mouseDown()" value="fasf"/>



function mouseDown(ev){

 count ++;
  timer = window.setTimeout(function(){
  if(count==1) alert(count);//结果是 单击1次 输出=1 双击 还是1  
  else alert(count);//三击 输出2 。。。晕。。。 没有道理啊。。。
  window.clearTimeout(timer);
  count=0;  
  },500)

}

求解

[解决办法]
我这里报count未定义的错。。
[解决办法]
解:

var mouseDown = (function(ev){
var count = 0,timer;
return function(){
count ++;
timer && window.clearTimeout(timer);
timer = window.setTimeout(function(){
if(count==1) alert(count);//结果是 单击1次 输出=1 双击 还是1
else alert(count);//三击 输出2 。。。晕。。。 没有道理啊。。。

count=0;
},500)
}

})();

热点排行
Bad Request.