Home>Article>Web Front-end> What to do if toggle cannot be used in jQuery

What to do if toggle cannot be used in jQuery

藏色散人
藏色散人 Original
2023-02-09 10:25:17 2233browse

The solution to the problem that toggle cannot be used in jQuery: 1. Rewrite part of the source code into a plug-in; 2. Introduce the plug-in into the web page, and then pass "$.fn.toggle = function( fn, fn2 ) { var args = arguments,guid = fn.guid || $.guid ,i=0,toggler = function( event ) {...}" can be used with toggle.

What to do if toggle cannot be used in jQuery

The operating environment of this tutorial: Windows 10 system, jquery version 1.9, DELL G3 computer

What to do if toggle cannot be used in jQuery ?

The solution to the failure of toggle() after version 1.9 of jQuery

Recently, I discovered that the toggle method of the higher version of jQuery is invalid. I found the solution before The source code of the version implements the toggle function, and I have seen many senior blogs and learned a lot...

First of all, when encountering this situation, we should first check the source code of the previous version for research, and try Just rewrite that part of the source code into a plug-in and introduce the plug-in into your own web page for long-term use.

$.fn.toggle = function( fn, fn2 ) { var args = arguments,guid = fn.guid || $.guid++,i=0, toggler = 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; }; toggler.guid = guid; while ( i < args.length ) { args[ i++ ].guid = guid; } return this.click( toggler ); }

What to do if toggle cannot be used in jQuery

Recommended learning: "jQuery Video Tutorial"

The above is the detailed content of What to do if toggle cannot be used in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Is node free? Next article:Is node free?