使用submitHandler禁用提交按钮 [英] Disable submit button with submitHandler

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

问题描述

我试图停止多次单击提交"按钮,并将同一项目多次上载到MySQL.

I am trying to stop a submit button to be clicked multiple times and upload the same item multiple times to MySQL.

因为验证不起作用,所以我完全不能按下按钮提交"按钮.这意味着我无法测试代码.

Because the validation doesn't work, I can not press the button submit button at all. Which means I can't test the code.

我也在运行相关文章这里,为您提供更多信息.

I am running related post as well here, to give you some more information.

$("#UploadForm").validate({

errorLabelContainer: "#messageBox",
        wrapper: "td",
        rules: {
            auction_description: {
                required: true
            },
            auction_int_postage_type: {
                required: true
            },
            listing_type: {
                required: true
            }
        }

   //all your options here

   submitHandler:function(form){
       $('#submit').attr('disabled','disabled');
   }
});

HTML

 <form method="post" name="UploadForm" id="UploadForm"
 action="upload.php" enctype="multipart/form-data" >


 <input style="text-transform:none;"  type="text" class="button_date" 
 name="auction_bin_price" id="auction_bin_price" value="" size="15" />

 <input class="button2" style="border-right:none; font-size:13px;"
 name="List Item" id="submit" type="submit" value="List Item"/>

 </form>

推荐答案

这是 小提琴 ,其中有一个有效的解决方案演示.

Here is a fiddle that has a working demo of solution to your problem.

要更改disabled属性,应使用 .prop() 函数.

To change the disabled property you should use the .prop() function.

$("#submit").prop('disabled', true);
$("#submit").prop('disabled', false);

jQuery 1.5及以下版本

.prop()函数不存在,但是 .attr() 的作用类似:

jQuery 1.5 and below

The .prop() function doesn't exist, but .attr() does similar:

设置禁用的属性.

$("#submit").attr('disabled','disabled');

再次启用

$("#submit").removeAttr('disabled');

在任何版本的jQuery中

您始终可以依赖于实际的DOM对象,并且如果只处理一个元素,它可能会比其他两个选项快一点:

In any version of jQuery

You can always rely on the actual DOM object and is probably a little faster than the other two options if you are only dealing with one element:

// assuming an event handler thus 'this'
this.disabled = true;

使用.prop().attr()方法的优点是可以为一堆选定项设置属性.

The advantage to using the .prop() or .attr() methods is that you can set the property for a bunch of selected items.

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

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