禁用后点击提交按钮 [英] Disabling a submit button after one click

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

问题描述

下面是我的code:

<form name='frm' id='frm' action='load.asp' method='post' onSubmit='return OnSubmit(this)' style='margin-top:15px'>
    <input type='submit' name='send' id='send' onclick="this.disabled=true;return true;" value='Send' title='test'>
</form>

我要执行我的onsubmit功能,我想所需提交的页面。
在我的网站,不提交和无功能

I want my onsubmit function to be executed and I want the page to be submited. In my website, no submit and no function

我试着在这里重复它,但形式似乎被张贴和我的函数不被执行...
http://jsfiddle.net/V7B3T/1/

I've tried to duplicate it here, but the form seems to be posted and my function never gets executed ... http://jsfiddle.net/V7B3T/1/

和我不知道什么时候我应该重新启动按钮。

And I don't know when I should reactivate the button.

我应该做的的document.ready,还是在功能的onsubmit

Should I do it in the document.ready, or in the onSubmit function ?

因此​​,如果有人能固定小提琴:),之后我将它与我的code比较。
我想:•我迷路了。

So if someone can fixed the fiddle :) and after that I'll compare it with my code. I think :S I'm lost

感谢所有

推荐答案

如果您想验证的形式或做任何修改的提交和只提交如果表单是有效的,你可以做这样的事情之前:

If you want to validate the form or make any changes the before submitting and only submit if the form is valid you can do something like this:

<form id="frm" action="load.asp" method="post" enctype="multipart/form-data">
    <input type="submit" name="send" id="send" value="Send" title="test">
</form>

和JavaScript的code:

and the JavaScript code:

$('#frm').bind('submit', function (e) {
    var button = $('#send');

    // Disable the submit button while evaluating if the form should be submitted
    button.prop('disabled', true);

    var valid = true;    

    // Do stuff (validations, etc) here and set
    // "valid" to false if the validation fails

    if (!valid) { 
        // Prevent form from submitting if validation failed
        e.preventDefault();

        // Reactivate the button if the form was not submitted
        button.prop('disabled', false);
    }
});

下面是一个工作小提琴

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

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