Home >Web Front-end >Front-end Q&A >How to use jquery1.9.1 toggle method
jquery1.9.1 How to use toggle: 1. Open the corresponding js code; 2. Add the "$.fn.toggle = function(fn, fn2) {...}" code to the js. Bind the toggle function to the element.
The operating environment of this article: windows7 system, jquery1.9.1 version, DELL G3 computer
jquery1.9.1 How to use the toggle method?
How to use the toggle function in jquery1.9 or above?
The toggle() method is used to bind two or more event handler functions to respond to the click event of the selected element in turn.
But this feature has been removed in versions 1.9 and above.
I feel that this function is quite good. The following is collected from the Internet. You can add the following code to js, and then you can bind the toggle function to the element.
$.fn.toggle = function( fn, fn2 ) { var args = arguments,guid = fn.guid || $.guid++,i=0, toggle = function( event ) { var lastToggle = ( $._data( this, "lastToggle" + fn.guid ) || 0 ) % i; $._data( this, "lastToggle" + fn.guid, lastToggle + 1 ); event.preventDefault(); return args[ lastToggle ].apply( this, arguments ) || false; }; toggle.guid = guid; while ( i < args.length ) { args[ i++ ].guid = guid; } return this.click( toggle ); };
Recommended learning: "jquery video tutorial"
The above is the detailed content of How to use jquery1.9.1 toggle method. For more information, please follow other related articles on the PHP Chinese website!