在最新的JQuery的程序庫中jquery-2.2.3.js中已經(jīng)有好幾個(gè)函數(shù)被替換到了。應(yīng)該說版本過1.8或1.9時(shí)就淘汰了。
如:
.live() 1.9以上被淘汰。 替代函數(shù):.on()。
.die() 1.9以上被淘汰。 替代函數(shù):.off()。
.size() 1.8以上被淘汰。替代函數(shù):.length。
.toggle() 1.8以上被淘汰。
對(duì)于toggle,一般都會(huì)用if進(jìn)行替換。
如正常用toggle:
$(".one .top").toggle( function (){ $(".content").show(1500); $(".iocn").addClass("jian"); }, function (){ $(".content").hide("slow"); $(".iocn").addClass("jia"); } );
替換方法一:
$(".one .top").click(function() { if($(".content").css("display")=="none"){ $(".content").show(1500); $(".iocn").addClass("jian"); }else { $(".content").hide("slow"); $(".iocn").addClass("jia"); } });
當(dāng)然上面的替換方法有局限性。替換方法二:if語句。
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; } });
這樣就ok了。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com