【问题标题】:Submit button disabled after first click首次单击后禁用提交按钮
【发布时间】:2013-12-21 15:49:49
【问题描述】:

点击我网站上的“投稿”按钮后,会出现一个覆盖表单;但是,如果有人在提供信息之前立即单击“发送承诺”,则该按钮将被禁用(与 Stripe 按钮一样)以供进一步使用。因此,他们无法添加信用卡或提交表单;在他们刷新页面之前,它会被永久禁用。

如何更改它以使“发送承诺”按钮在第一次点击后仍处于活动状态?如果需要更多信息,请告诉我。

现场演示可以在这里找到:http://www.cantedpictures.com/9test/

否则:这里是js:

$(function(){
  $("#donateModal").on('show', function() {
    // Fix StripeButton sizing bug on Firefox and IE
    $(".stripe-button-inner, .stripe-button-inner iframe").width(132).height(36);
    // ensure button scrolls with the rest of the page
    $(".stripe-button-inner iframe").css('position', 'relative');
  });

  // Stripe Button Triggers formDomElement.submit().
  // We intercept it and notify user we have received the token
  var paymentForm = $('#payment-form')[0];
  paymentForm.original_submit = paymentForm.submit;
  paymentForm.submit = function() {
    $("#stripe-button-holder .stripe-button-inner").html(
        '<span class="label label-success">
        <i class="icon-ok"></i> Card Added</span>');
    return false;
  };

  $('#payment-form').validate({
      rules: {
      'first-name': {
        minlength: 1,
        required: true
      },
      'last-name': {
        minlength: 1,
        required: true
      },
      email: {
        required: true,
        email: true
      },
      amount: {
        required: true,
        min: 10,
      },
      'tos-agreed': {
        required: true
      }
      },
      messages: {
        'tos-agreed': 'You need to agree to the Terms of Service',
        'first-name': 'Please give us your first name',
        'last-name' : 'Please give us your last name',
        'email'     : 'Please give us your email so that we can contact you',
        'amount'    : 'Please pledge at least $10.'
      },
      errorPlacement: function (error, input) {
        $(input).closest('.controls').append(error);
      },
      highlight: function(el) {
        $(el).closest('.control-group').addClass('error');
      },
      unhighlight: function(el) {
        $(el).closest('.control-group').removeClass('error');
      },
      submitHandler: function(form) {
        // ensure CC info has been entered
        if (! $('[name=stripeToken]').val()) {
          $("#stripe-button-holder").closest('.control-group').addClass('error');
          $("#stripe-button-holder").append('<label class="error">
              Please Add Payment    Information</span>')
          window.location.reload();
        } else {
          form.original_submit();
        }
      }
  });
});//]]>  

【问题讨论】:

  • 我认为它没有为我禁用(我使用 chrome btw)
  • 我应该澄清一下:“贡献”按钮有效,但如果您立即单击它,“发送承诺”按钮将不起作用。单击“贡献”后,如果您立即单击“发送承诺”,则该按钮将永久禁用。

标签: javascript jquery stripe-payments


【解决方案1】:

您应该识别您的按钮并将下面的'button' 替换为'#myButtonId',但是一旦您这样做了,您就可以使用

$('button').prop('disabled', '');

删除禁用的属性。

【讨论】:

  • 嘿 Tomanow,我按照你说的方式更改了代码,但它仍然不起作用。你知道我哪里错了吗?我更改了 ID 并将 disabled 属性替换为: $('button').prop('disabled', '');
  • 您的 jQuery 选择器应该是按钮 ID。例如,如果您的按钮 id 是 myButton,请在要触发按钮被禁用的回调中执行 $('#myButton').prop('disabled', '');。
猜你喜欢
  • 1970-01-01
  • 2012-04-18
  • 2016-05-31
  • 1970-01-01
  • 2011-03-22
  • 1970-01-01
  • 2022-10-22
  • 2016-12-01
  • 1970-01-01
相关资源
最近更新 更多