简体   繁体   English

jQuery的步骤:提交表单时禁用提交按钮

[英]jquery-steps : disable submit button when form are submited

I'm using jquery-steps.js , 我正在使用jquery-steps.js,

I want to disable submit button when some one click on submit, and never activate it until the the form is submitted. 我想在单击提交时禁用提交按钮,并且在提交表单之前永远不要激活它。

The reason way is that if some one click on submit many time the I receive many mails! 原因是,如果某人单击多次提交,我会收到很多邮件!

Note : my HTML file does not include submit button , it is only show from the js file that I include bellow 注意:我的HTML文件不包含“提交”按钮,它仅从js文件中显示,其中包含以下内容

and my js file look like this. 和我的js文件看起来像这样。

$(function() {
    $("#smart-form").steps( {
        bodyTag:"fieldset", headerTag:"h2", bodyTag:"fieldset", transitionEffect:"slideLeft", titleTemplate:"<span class='number'>#index#</span> #title#", labels: {
            finish: "Send søknad", next: "Neste", previous: "Tilbake", loading: "Laster..."
        }
        , onStepChanging:function(event, currentIndex, newIndex) {
            if(currentIndex>newIndex) {
                return true;
            }
            var form=$(this);
            if(currentIndex<newIndex) {}
            return form.valid();
        }
        , onStepChanged:function(event, currentIndex, priorIndex) {}
        , onFinishing:function(event, currentIndex) {
            var form=$(this);
            form.validate().settings.ignore=":disabled";
            return form.valid();
        }
        , onFinished:function(event, currentIndex) {
            var form=$(this);
            $(form).ajaxSubmit( {
                target:'.result', beforeSubmit:function() {}
                , error:function() {}
                , success:function() {
                    $('.alert-success').show().delay(7000).fadeOut();
                    $('.field').removeClass("state-error, state-success");
                    if($('.alert-error').length==0) {
                        $('#smart-form').resetForm();
                        reloadCaptcha();
                    }
                }
            }
            );
        }
    }

这可能有点通用(我还没有测试过),但是可以帮助您入门

$(document).find('input[type="submit"').prop('disabled', 'disabled');

After the first line $(function() { , add : 在第一行$(function() { ,添加:

var isFinishing = false;

In the onFinished event change this line : onFinished事件中,更改以下行:

var form=$(this);

for : 为:

if (isFinishing) return;

isFinishing = true;
var form=$(this);

If the success event of the AJAX call isn't reloading the page, you shall consider adding this line within this function : 如果AJAX调用的success事件没有重新加载页面,则应考虑在此函数中添加以下行:

isFinishing = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM