When I wrote an example recently, I used the toggle function, but the element would be hidden when called. Previously, it only switched between multiple events in turn. I was puzzled, so I searched online to view the jQuery API documentation. Finally found the reason:
It turns out that toggle() has changed after jQuery 1.9. The following are the Notes from the official website:
Note: This method signature was deprecated in jQuery 1.8 and removed in jQuery 1.9. jQuery also provides an animation methodnamed .toggle() that toggles the visibility of elements. Whether the animation or the event method is fired depends on the set of argumentspassed.
In earlier versions, there were two toggle() with the same name, but the execution The method is different:
.toggle( handler(eventObject), handler(eventObject) [, handler(eventObject) ] )
Description: Bind two or more handlers to the matched elements, to be executed on alternate clicks.
============================================ =========
.toggle( [duration ] [, complete ] )
Description: Display or hide the matched elements.
And later versions replace the first toggle() function It was removed, which caused the element to be hidden when it was used to call the switching function.
========================
Since this function has been removed, it is still needed to implement the requirements. How to realize the switching of multiple events in turn?
It can be triggered by judging different situations through the click event, or by setting a variable to count the number of clicks to execute different functions.