禁用在单击元素后点击元素 [英] Disabling an element from being clicked after it is clicked

查看:162
本文介绍了禁用在单击元素后点击元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,用于保存用户编辑的内容。我不希望他们多次点击保存按钮,因为它导致在服务器上的负载。我想在他们点击它后禁用按钮。
这是我尝试的(不工作,虽然):

I have a button that saves the content that a user edits. I do not want them to hit the save button multiple times because of the load it causes on the server. I want to disable the button after they click on it. Here is what I have attempted(doesn't work, though):

  var active = true;
  $("#save").click(function() {
    if (!active) return;
    active = false;
........
........
........
    active = true;

问题是用户仍然可以多次点击元素
我如何解决这个问题?

The problem is that the user can still click on the element multiple times. How can I fix this problem?

编辑:对不起,我忘了提及我想在onc​​lick代码完成执行后启用点击。

Sorry, I forgot to mention that I want to enable the click after the onclick code has finished executing.

推荐答案

$("#save").one('click', function() {
    //this function will be called only once even after clicking multiple times
});

这篇关于禁用在单击元素后点击元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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