clickEvent and mousedown event are generally easy to distinguish in jquery, but in some cases developers will give priority to the click event instead of Accurately locate events. This happens when we get the event values of each mouse button.
Simple conceptual distinction:
click: refers to when the mouse is placed on a certain web page element, a click action is triggered on the element. This process is the click event. .click() can call a response function to respond to the click event and generate some actions.
mousedown: refers to the process when your finger presses any key on the mouse before releasing it. This process does not actually include the moment when the key is pressed. This moment is very short. , mousedown is a process in which you press and hold down without releasing. This process can be lengthy and is significantly different from mouseup.
The simplest way to distinguish two events is that one occurs on the computer screen and the other occurs on the mouse.
So how should we choose these two different events when we encounter some specific problems? To give a very simple example: I clicked an expand button to expand an element. Now, I need to click on other areas outside the element to automatically collapse it.
It seems very simple. When we see the word "click", the first thing we think of is how to use the click event to accomplish this goal. However, I chose the mousedown event, because during this process, I considered that the desired result is only when the user clicks the left mouse button to trigger the action. The user does not want to have the same effect when clicking the middle or right button. When we need to use an event.which judgment, we will encounter very big problems when judging which. Please see this article and this article for details. The trigger of the click event does not The attribute of which is only available for mousedown or mouseup triggers (mouse). Therefore, if you want to use which attribute, it is best to consider the mousedown/mouseup event rather than the click event.
The above is the detailed content of How to distinguish between mousedown and click in jquery event?. For more information, please follow other related articles on the PHP Chinese website!