What is alternative to use after jQuery 1.9 removed .toggle(function,function)?

时间秒杀一切 提交于 2019-11-27 09:02:47

With two states, you can just maintain the current toggled state as a boolean (I used clickState). If you wanted to have multiple states, you could continue to add 1 to the state count and then check the modulus of the total count to determine which function should fire based on the state.

I updated your code a bit since ele is actually the jQuery object you want to work with:

http://jsfiddle.net/TNAC6/2/

Raj Sharma
$(document).ready(function() {
    var flag=0;
    $('selector').on('click', function(){
        var menu = $("element_to_toggle");
        if(flag==0){
            menu.text("click one");
            flag=1;
            return;
        }
        else if(flag==1){
            menu.text("click two");
            flag=0;
            return;
        }
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!