简体   繁体   English

单击按钮提交时如何禁用操作表单?

[英]How can I disable action form when click button submit?

My html code like this :我的 html 代码是这样的:

<form id="payment-form" method="POST" action="http://myshop.dev/member/shop/payment/process">
    ...
    <button class="btn btn-danger pull-right" type="submit" >
        Checkout
    </button> 
</form

My javascript code like this :我的 javascript 代码是这样的:

//check if there is exist button forward browser or no
if (window.performance && window.performance.navigation.type == window.performance.navigation.TYPE_BACK_FORWARD) {
    //disable action form
    $('#payment-form').attr('action', '')
    //call forward button on the browser
    history.go(1);
}
else {
    //display checkout detail
    $('#payment-form').attr('action', '/member/shop/payment/checkout')
    return true
}

I have a checkout button on the cart details of a purchase.我在购买的购物车详细信息上有一个结帐按钮。 If the user clicks the checkout button then it will show checkout details of a purchase如果用户点击结帐按钮,那么它将显示购买的结帐详细信息

If the user clicks back button in browser, it will return to previous page, that is detail cart.如果用户在浏览器中点击后退按钮,它将返回上一页,即详情购物车。 If on that page, the user clicks the checkout button again, I want to : it will call the forward button in the browser如果在该页面上,用户再次单击结帐按钮,我想:它将调用浏览器中的前进按钮

My problem is if the user clicks on the checkout button again, the action form is still working and there is still a refresh page我的问题是如果用户再次点击结帐按钮,操作表单仍然有效并且仍然有刷新页面

I want when the user clicks the second checkout button, it just call forward button in the browser and no refresh page我希望当用户单击第二个结帐按钮时,它只是在浏览器中调用前进按钮而没有刷新页面

How can I do it?我该怎么做?

<form action="javascript:void(0);" > </form>

I'm not sure I understand exactly what are you trying to do or why do it that way, but first, in my opinion, it is a horrible idea to control the flow of your site/web-app through the browser's history.我不确定我是否完全理解您想要做什么或为什么要这样做,但首先,在我看来,通过浏览器的历史记录控制您的网站/网络应用程序的流量是一个可怕的想法。 Second, have you tried disabling the default behavior of the form's submit event?其次,您是否尝试过禁用表单提交事件的默认行为?

For instance:例如:

$("#payment-form").submit(function(event) {
    // this takes care of disabling the form's submission
    event.preventDefault();

    // the rest of your code...
});

I'm guessing you're going to want to add some condition to that function so that the form's submission is only disabled if the user tries to click the checkout button again (if I understood correctly).我猜您会想要向该函数添加一些条件,以便仅在用户尝试再次单击结帐按钮时才会禁用表单提交(如果我理解正确的话)。 Anyway, let me know if this was helpful at all, and if it's not, try to explain a little bit more of why are you trying to do things this way and what exactly is the issue.无论如何,让我知道这是否有帮助,如果没有,请尝试更多地解释您为什么要以这种方式做事以及问题到底是什么。 Hope it helped.希望它有所帮助。

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

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