alternate between two functions on click

前端 未结 2 1837
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 19:37

How do I alternate between calling two functions on click? For example, here is the button

and here is the j

相关标签:
2条回答
  • 2021-01-20 20:17

    Use jQuery's toggle() method

    $("#fooButton").toggle(fooOne, fooTwo);
    

    Edited to make use of your named functions rather than sloppily using anonymous ones.

    0 讨论(0)
  • 2021-01-20 20:20

    You can use the toggle pseudo-event:

    $('#fooButton').toggle(fooOne, fooTwo);
    

    Note: This is deprecated as of jQuery 1.8 and removed in jQuery 1.9+. You can use jQuery-migrate if you need this function anyway.

    0 讨论(0)
提交回复
热议问题