What is the best approach for (client-side) disabling of a submit button?((客户端)禁用提交按钮的最佳方法是什么?)
问题描述
详情:
- 仅在用户点击提交按钮后禁用,但在回发到服务器之前
- ASP.NET 网络表单 (.NET 1.1)
- 更喜欢 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 禁用按钮)并且您这样做是为了保护同一表单的多次提交,那么您应该在代码中进行某种控制处理提交的数据,因为使用 javascript 禁用按钮可能不会阻止多次提交.
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.
这篇关于(客户端)禁用提交按钮的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:(客户端)禁用提交按钮的最佳方法是什么?


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01