简体   繁体   English

第一次单击后如何禁用“完成”按钮

[英]How to disable Finish button after first click

I've tried the various methods that normally work, but it seems SmartWizard is preventing these methods from working. 我已经尝试了通常可以使用的各种方法,但是SmartWizard似乎阻止了这些方法的工作。

I need to disable the Finish button and change the text after it is clicked to prevent multiple submissions. 我需要禁用“完成”按钮并在单击后更改文本,以防止多次提交。 No matter where I place the code, the screen does not change, the value of the button does not change, and the button does not disable. 无论我在哪里放置代码,屏幕都不会改变,按钮的值不会改变,并且按钮也不会禁用。

I tried the typical click function... 我尝试了典型的点击功能...

$(".actionBar .buttonFinish").click(function(){
    $(".actionBar .buttonFinish").addClass("buttonDisabled");
    $(".actionBar .buttonFinish").text("Sending...");
});

I also tried using this as part of the final step validation and in the FinishCallback right before the ajax call. 我还尝试将其用作最后一步验证的一部分,并且在ajax调用之前的FinishCallback中使用。 Nothing changes until AFTER the ajax call is completed and the ajax success runs. 直到ajax调用完成并且ajax成功运行之后,一切都没有改变。

UPDATE 更新

Ok, this is for sure a timing issue. 好的,这肯定是时间问题。 If I cause the ajax call to fail, the button disables and the text changes. 如果我导致ajax调用失败,则该按钮将禁用并且文本会更改。 I need to make sure these two things occur before moving on to the ajax call. 在继续进行ajax调用之前,我需要确保这两件事发生。 So far, I tried this but it did not work: 到目前为止,我尝试了此操作,但没有成功:

$(".actionBar .buttonFinish").addClass("buttonDisabled").text("Sending...").ajax({
$(".actionBar .buttonFinish").click(function(){
   $(".actionBar .buttonFinish").attr('disabled', 'disabled');
   $(".actionBar .buttonFinish").text("Sending...");
});

you can add this at the end of the 'onclick' event to disable the button 您可以在'onclick'事件的末尾添加此内容以禁用该按钮

$(this).prop( "disabled", true );

OR 要么

$(this).attr("disabled", 'disabled');

you need to use the function 'prop' or 'attr' depending on the jquery version 您需要根据jQuery版本使用函数“ prop”或“ attr”

Try this. 尝试这个。

 $(document).ready(function(){ $(function(){ $(".buttonFinish").on("click", function(){ $(this).prop('disabled', true); $(this).val("Sending..."); }); }); }); 
 input{ display: block } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <div> <form> <input type="text"> <input type="text"> <input class="buttonFinish" type="submit"> </form> </div> 

UPDATE 更新

Let me see if I understood you, you want to disable the button and the text before ajax call? 让我看看是否理解您,是否要在ajax调用前禁用按钮和文本? You've tried with beforeSend? 您尝试过使用beforeSend吗?

 $(document).ready(function(){ $(function(){ $("form").submit(function(e){ e.preventDefault(); $.ajax({ beforeSend: function(){ $(".buttonFinish").prop('disabled', true); $(".buttonFinish").val("Sending..."); }, complete: function(){ // remove disabled and change the text }, }); }); }); }); 
 input{ display: block } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <div> <form> <input type="text"> <input type="text"> <input class="buttonFinish" type="submit"> </form> </div> 

Since your .buttonFinish is a link , not actually a button , you can't disable it with .prop('disabled', true) — you may want to use a "blocking pane" instead. 由于您的.buttonFinish链接 ,实际上不是按钮 ,因此无法使用.prop('disabled', true)禁用它-您可能想使用“阻止窗格”。

Put a div at the very end of your page, I prefer just before the </body> tag, that contains nothing and is unseen, off the page and with no height and width. 在页面的最后放置一个div,我更喜欢在</body>标记之前,该标记不包含任何内容且看不见,位于页面之外,并且没有高度和宽度。

    <div id="blocker"></div>
</body>

When the "button" is clicked then add a class on it that will make it show, using the full height/width of the page and with a high z-index so it is "in front" of everything else; 单击“按钮”后,在其上添加一个类,该类将使用页面的整个高度/宽度并具有较高的z-index值,使其位于所有其他内容的“前面”; it will get all the clicks which won't pass through to the controls underneath it as a lower z-index. 它将获得所有不会传递到其下方控件的点击,作为较低的Z索引。
Your click handler would include $('blocker').addClass('blocking'); 您的点击处理程序将包括$('blocker').addClass('blocking'); giving the resulting DOM ... 给最终的DOM ...

    <div id="blocker" class="blocking"></div>
</body>

Use CSS to style #blocker so it is unseen, then style #blocker.blocking so it blocks the rest of the page. 使用CSS设置#blocker样式以使其不可见,然后使用#blocker.blocking样式以使其阻止页面的其余部分。

 $('a.finished').click(function(e) { e.preventDefault(); $('#blocker').addClass('blocking'); // when ajax call finishes, // use $('#blocker').removeClass('blocking'); }); 
 #blocker { position: fixed; top: -10px; left: -10px; height: 0; width: 0; z-index: -20; background-color: white; } #blocker.blocking { height: auto; width: auto; bottom: -10px; right: -10px; opacity: 0.6; z-index: 9000; } 
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.js"></script> <div class="stuff"> <p>This is stuff</p> <p>This is other stuff</p> <p>A <a href="#" class="finished">link</a> is in here.</p> </div> <div id="blocker"></div> 

Try this 尝试这个

<input type='button' id='btn' onclick='click_me()' value='click'>

  var disable = false;
  function click_me()
  {
    if(disable = 'false') {
      $(".actionBar .buttonFinish").addClass("buttonDisabled");
      $(".actionBar .buttonFinish").text("Sending...");
      disable = true;
    }
  }

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

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