仅执行一次功能 [英] Executing function only once

查看:114
本文介绍了仅执行一次功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个访客可以注册的注册表,当他们按下提交"按钮时,包含该注册表的div会稍微向左移动,使其出现在中间.

I have a register form where visitors can sign up, and when they press the submit button the div containing the register form is being moved slightly to left so that it appears in the middle.

执行该操作的代码可以正常工作,但是如果访问者在注册表中写错了内容,则他们需要能够再次尝试,但是如果重复几次,注册表将再次被移动.将完全移出容器.

The code doing that works fine, but if the visitor has wrote something wrong in the register form they need to be able to try again, but then the register form will be moved once again, if this is repeated a few times it will move out of the container totally.

如何仅触发一次功能?这是我当前的代码:

How can I trigger a function only once? Here is my current code:

...

$('#form form').submit(function(){

// Some code for showing "loading" image etc..

});

推荐答案

您可以使用 one()通话

$('#form form').one('submit', function(){

// Some code for showing "loading" image etc..

});

那么它只会在第一次被触发.

Then it will only be fired the first time.

这篇关于仅执行一次功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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