onclick and ondblclick functions being separated

When I double click an element, the flow is being executed with a single click function followed by the double click function and this is not I like to have.

I search for the solution of having two unique functions for either single click and double click and this is it here, I modified the code though:

var timer;
var status=1;
function clickIt(a,b){
if(a==1){//single click
status=1;
timer = setTimeout(function() {
if(status==1)dosomething(b);// this will disable the single click if double click take charge
}, 1000);
}
else {//double click
status=2;
if(timer)clearTimeout(timer);// this will disable the single click if double click take charge
doanother(b);
}
}

The element being trigged to call the the function for either onclick or ondblclick but not both is as such:
<a onclick="clickIt(1,’parameter_1′)" ondblclick="clickIt(2,’parameter_2′)">….</a>

Happy coding!

廣告
Posted in 未分類