jQuery click / toggle between two functions

前端 未结 10 1658
野的像风
野的像风 2020-11-22 07:58

I am looking for a way to have two separate operations / functions / \"blocks of code\" run when something is clicked and then a totally different block when the same thing

10条回答
  •  自闭症患者
    2020-11-22 08:49

    I would do something like this for the code you showed, if all you need to do is toggle a value :

    var oddClick = true;
    $("#time").click(function() {
        $(this).animate({
            width: oddClick ? 260 : 30
        },1500);
        oddClick = !oddClick;
    });
    

提交回复
热议问题