jquery-steps:提交表单时禁用提交按钮 [英] jquery-steps : disable submit button when form are submited

查看:516
本文介绍了jquery-steps:提交表单时禁用提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery-steps.js

I'm using 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!

注意:我的HTML文件不包含提交"按钮,它仅显示在我包含波纹管的js文件中

Note : my HTML file does not include submit button , it is only show from the js file that I include bellow

和我的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();
                    }
                }
            }
            );
        }
    }

推荐答案

第一行$(function() {之后,添加:

var isFinishing = false;

onFinished事件中,更改以下行:

In the onFinished event change this line :

var form=$(this);

用于:

if (isFinishing) return;

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

如果AJAX调用的success事件没有重新加载页面,则应考虑在此函数中添加以下行:

If the success event of the AJAX call isn't reloading the page, you shall consider adding this line within this function :

isFinishing = false;

这篇关于jquery-steps:提交表单时禁用提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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