Generally, onclick can be considered as a collection of onmousedown and onmouseup. Onclick is generally used to deal with the instant click effect, while onmousedown and onmouseup are mainly used to deal with effects with time intervals, such as the effect of dragging and parking the mouse.
Conflict scenarios:
If an object contains both onclick and onmousedown. If you click this object, these three objects are triggered at the same time. If we only want the single-host effect, but unfortunately, it triggers onmousedown and onmouseup, and I don't want to trigger onmousedown or onmouseup at all.
Solution:
Call the code in onmousedown asynchronously using setTimeout. The interval is 200 ms.
If the time between Down and up is
1)> 200 ms, call onmousedown and onmouseup
2) <= 200 ms, call the Click Event
Code: (using jquery code as an example)
VaR mousedownanduptimer = NULL; var onmousedownflag = false; $ (element ). click (function () {// click code in here}); $ (element ). mousedown (function () {onmousedownflag = false; mousedownanduptimer = setTimeout (function () {// onmousedown code in here onmousedownflag = true ;}, 200 );}). mouseup (function () {If (onmousedownflag) {// onmouseup code in here} else {cleartimeout (mousedownanduptimer); // clear delay time }});