Home > Web Front-end > JS Tutorial > body text

JQuery: Sharing of alternative methods after toggle time is eliminated

黄舟
Release: 2017-06-26 13:39:50
Original
1965 people have browsed it

In the latest JQuery library, several functions have been replaced in jquery-2.2.3.js. It should be said that it will be eliminated after version 1.8 or 1.9.

For example:

  1. .live() 1.9 or above will be eliminated. Alternative function: .on().

  2. .die() was eliminated above 1.9. Alternative function: .off().

  3. .size() 1.8 or above will be eliminated. Alternative function: .length.

  4. .toggle() 1.8 or above will be eliminated.

    For toggle, it is generally replaced with if.
    Use toggle normally:

$(".one .top").toggle(        function (){
             $(".content").show(1500);
             $(".iocn").addClass("jian");

        },        function (){
             $(".content").hide("slow");
               $(".iocn").addClass("jia");

        }
        );
Copy after login

Replacement method one:

$(".one .top").click(function() {
            if($(".content").css("display")=="none"){
                 $(".content").show(1500);
                 $(".iocn").addClass("jian");
            }else {

                 $(".content").hide("slow");
                 $(".iocn").addClass("jia");
            }

        });
Copy after login

Of course, the above replacement method has limitations. Replacement method two: if statement.

var i=0;
        $(".one .top").click(function() {
            if(i==0){
                 $(".content").hide("slow");
                 $(".iocn").addClass("jia");
                 i=1;
            }else  {
                 $(".content").show(1500);
                 $(".iocn").addClass("jian");
                 i=0;
            }

        });
Copy after login

That’s ok.

The above is the detailed content of JQuery: Sharing of alternative methods after toggle time is eliminated. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template