Disable submit button with submitHandler

前端 未结 1 799
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 05:47

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 pre

相关标签:
1条回答
  • 2020-12-07 06:21

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

    jQuery 1.6+

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

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

    jQuery 1.5 and below

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

    Set the disabled attribute.

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

    To enable again

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

    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;
    

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

    0 讨论(0)
提交回复
热议问题