The example in this article describes the method of javascript to achieve the coexistence of single click and double click. Share it with everyone for your reference. The specific analysis is as follows:
In the process of web development, we often encounter such a problem, registering a double-click event for a link, or registering a click or double-click event on a button or other element at the same time. At this time, we found that the double-click event in the web page Events never seem to work because when we click once, they are intercepted by a hyperlink or click event. This article describes a specific method on how to solve this technical problem. The implementation principle of this solution is that both single-click and double-click events call the same method. We determine whether it is a single-click or double-click event based on the time between two mouse clicks. When the click event comes, do not call it first, wait for a short period of time, after this period of time, if the next click does not come, start calling the corresponding operation of the click, if there is the next click, call the double click.
For detailed description, please join the code list below:
onclick=" handleWisely(event.type)"
ondblclick=" handleWisely(event.type)"
style=" color: blue; font-family: arial; cursor: hand" >
点击一下看看结果:
希望本文所述对大家的javascript程序设计有所帮助。