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

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)
}

})();