Solution to toggle () hiding problems
The toggle function is used in an instance, but the elements are hidden during the call. After searching, the cause is found. For more information, see
Recently I used the toggle function when writing an instance, but the elements will be hidden during the call. Previously I used multiple events in turn. The best way to do this is to search and view the jQuery API documentation on the internet. I finally found the cause:
After jQuery 1.9, toggle () has changed. The following is the official Notes:
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 methods executed were 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.
In later versions, the first toggle () function is removed, causing the elements to be hidden when the switching function is called.
======================================
Since this function is removed, the implementation requirement is still required. How can we achieve switching between multiple events in turn?
You can use the click event to determine different conditions, or set a variable to count the number of clicks to execute different functions.
The Code is as follows:
Var num = 0;
$ ('# Click'). click (function (e ){
If (num ++ % 2 = 0 ){
// DoSomething
} Else {
// DoOtherSomething
}
E. preventDefault (); // block the default action of an element (if any)
});