问题描述
详情:
- 仅在用户点击提交按钮后禁用,但在回发到服务器之前
- 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.
这篇关于(客户端)禁用提交按钮的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!