Home >Web Front-end >JS Tutorial >JQuery: Sharing of alternative methods after toggle time is eliminated

JQuery: Sharing of alternative methods after toggle time is eliminated

黄舟
黄舟Original
2017-06-26 13:39:501968browse

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");

        }
        );

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");
            }

        });

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;
            }

        });

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!

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