单击时在两个功能之间交替 [英] alternate between two functions on click

查看:76
本文介绍了单击时在两个功能之间交替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单击时调用两个函数之间交替?例如,这是按钮

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

<div id="fooButton" />

这是JavaScript

and here is the javascript

function fooOne() {
     alert('foo One called');
}

function fooTwo() {
     alert('foo Two called');
}

如何在备用按钮单击时调用fooOne()和fooTwo()?

how do I call fooOne() and fooTwo() on alternate button clicks?

推荐答案

您可以使用切换伪-事件:

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

注意:此版本自jQuery 1.8起已弃用,并已在jQuery 1.9+中删除.如果仍然需要此功能,则可以使用 jQuery-migrate .

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.

这篇关于单击时在两个功能之间交替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆