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

后端 未结 2 1866
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 18:10

Hi i\'m trying to create something that will alternate shrinking and growing on every click, but i\'m using jQuery 1.9 for my website. the .toggle(functio

相关标签:
2条回答
  • 2020-12-01 18:38

    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/

    0 讨论(0)
  • 2020-12-01 18:56
    $(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;
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题