什么是(客户端)禁用提交按钮的最好的方法? [英] What is the best approach for (client-side) disabling of a submit button?

查看:104
本文介绍了什么是(客户端)禁用提交按钮的最好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

详细内容:


  • 只有用户点击提交按钮之后,但在发布之前返回到服务器
  • 禁用
  • ASP.NET Web表单(.NET 1.1)

  • preFER的jQuery(如有库在所有)

  • 必须启用如果重载形式(即刷卡失败)

这是不是必须的,我这样做,但如果有一个简单的方法来做到这一点,而无需改变太多,我会做到这一点。 (即,如果没有一个简单的解决办法,我可能不会做,所以不用担心挖得太深)

This isn't a necessity that I do this, but if there is a simple way to do it without having to change too much, I'll do it. (i.e. if there isn't a simple solution, I probably won't do it, so don't worry about digging too deep)

推荐答案

对于所有提交按钮,通过jQuery,这将会是:

For all submit buttons, via JQuery, it'd be:

$('input[type=submit]').click(function() { this.disabled = true; });

也可能是更有帮助的表单提交这样做的:

Or it might be more useful to do so on form submission:

$('form').submit(function() {
    $('input[type=submit]', this).attr("disabled","disabled");
});

但我认为,我们可以提供更好的回答你的问题,如果我们知道更多的有关内容。

But I think we could give a better answer to your question if we knew a bit more about the context.

如果这是一个Ajax请求,那么你需要确保你启用成功或失败再次提交按钮。

If this is an ajax request, then you'll need to make sure you enable submit buttons again on either success or failure.

如果这是一个标准的HTTP表单提交(除了禁止使用JavaScript的按钮),你这样做是从同一形式的多个提交安全防范,那么你应该有某种控制在code,与提交的数据交易,因为禁用按钮与JavaScript可能不会prevent一稿多投。

If this is a standard HTTP form submission (aside from disabling the button with javascript) and you're doing this to safe guard from multiple submissions of the same form, then you ought to have some sort of control in the code that deals with the submitted data, because disabling a button with javascript might not prevent multiple submissions.

这篇关于什么是(客户端)禁用提交按钮的最好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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