首次单击Jquery时禁用提交按钮 [英] Disable submit button on first click with Jquery

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

问题描述

我目前有一个灯箱弹出窗口附加到提交按钮,该按钮仅在第一次单击提交按钮时显示。基本上在有人提交表单之前,我们希望他们在点击提交按钮时看到这个弹出窗口。并且一切正常,但现在我需要将其发送到第一次点击的位置,表单不提交/处理。但是,在第一次点击之后,需要启用提交按钮以便他们可以提交表单。

I currently have a lightbox popup attached to a submit button that shows only the first time the submit button is clicked. Basically before someone submits a form, we want them to see this popup when they hit the submit button. And that all works fine, but now I need to make it to where on that first click, the form doesn't submit/process. However, after that first click, the submit button would need to be enabled to where they can submit the form.

任何想法如何将以下代码更改为提交的位置按钮不会仅在第一次单击提交按钮时处理表单?

Any idea how to change the below code to where the submit button does not process the form only the first time the submit button is clicked?

   <script type="text/javascript">
    $('#Submitbutton').one("click",function(e) {

    $('#lp').lightbox_me({
    centered: true,
    overlayCSS:{background: '#481d33', opacity: .45},
    overlaySpeed:0,
    lightboxSpeed:0
    });

    });
    </script>


推荐答案

var hasClicked = false;
$('#Submitbutton').on('click',function(e) {
    if (hasClicked === true) {
        //submit form here
    } else {
        e.preventDefault();
        hasClicked = true;
        $('#lp').lightbox_me({
            centered: true,
            overlayCSS:{background: '#481d33', opacity: .45},
            overlaySpeed:0,
            lightboxSpeed:0
        });
    }
});

在第一次提交时设置变量,然后在第二次提交时根据该变量执行不同的操作。

Sets a variable on first submit, then on second submit does something different because of that variable.

编辑:一致的报价和代码清理。

Consistent quotes and code cleanup.

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

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