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:
.live() 1.9 or above will be eliminated. Alternative function: .on().
.die() was eliminated above 1.9. Alternative function: .off().
.size() 1.8 or above will be eliminated. Alternative function: .length.
.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!