简体   繁体   English

我如何防止重复提交

[英]How can i prevent double submission of <a href>

Good Day Guys ! 大家好!

I have a problem here 我这里有问题

I have 3 我有3个

      <a href="{$baseUrl}/default/report/download-ready-prompt?id={$order.id}" name ="ahref" id="promptButton" class="button-blue printing">Prompt</a> &nbsp;

      <a href="{$baseUrl}/default/report/download-ready-cert?id={$order.id}" name = "ahref" id="certButton" class="button-blue printing withSignature">Cert</a> &nbsp; 

      <a href="{$baseUrl}/default/report/download-ready-invoice?id={$order.id}" name ="ahref" id="invoiceButton" class="button-blue printing withSignature">Invoice</a> &nbsp;

These 3 links load in the same page 这3个链接在同一页面中加载

if a click one link it will download. 如果单击一个链接,它将下载。 but if i click it again i will not download 但是,如果我再次单击它,我将不会下载

because i input a javascript like this 因为我输入了这样的JavaScript

    <script type="text/javascript"> 
    {literal}
        $(document).ready(function(){
             var submitStatus = false;
        $('a#promptButton').click(function(e){
             if (!submitStatus) {
               submitStatus = true;
        } else {
             e.preventDefault();
        }
        });
        $('a#certButton').click(function(e){
           if (!submitStatus) {
          submitStatus = true;
         } else {
        e.preventDefault();
        }
        });
        $('a#historyButton').click(function(e){
        if (!submitStatus) {
          submitStatus = true;
        } else {
          e.preventDefault();
        }
        });
        $('a#invoiceButton').click(function(e){
        if (!submitStatus) {
           submitStatus = true;
        } else {
           e.preventDefault();
        }
        });
        });
      {/literal}
      </script>

What will be my code if i want to download twice but i will prevent double submission? 如果我想下载两次但我将阻止重复提交,我的代码将是什么? Anybody can help me Please :( 任何人都可以帮助我:(

This sample code may help to solve your issue. 此示例代码可能有助于解决您的问题。

HTML HTML

<a href="http://www.google.com" target="_blank" >Google</a>
<a href="http://www.yahoo.com"  target="_blank">Yahoo</a>
<a href="http://www.stackoverflow.com"  target="_blank">Stackoverflow</a>

JS: JS:

$('a').click(function(e){
    $this = $(this);
    if($this.data('disabled') == 'true'){
        e.preventDefault();
        setTimeout(function(){$this.data('disabled', 'false')}, 10); //Enable the anchor tag after 10 milliseconds
    }else{
        $this.data('disabled', 'true');
    }    
});

Demo: http://jsfiddle.net/rUrk4/6/ 演示: http //jsfiddle.net/rUrk4/6/

I have simple solution for you, 我为您提供简单的解决方案,

Just put this jQuery code after including JQuery ofcourse 只需在包含课程的JQuery之后放置此jQuery代码

<script type="text/javascript" src ="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>

<script type="text/javascript">$('a:visited').click(function(){return false;});</script>

this will prevent click on all visited links in your page. 这样可以防止点击页面中所有已访问的链接。 :) :)

So first time the click will work second time will not.. 因此,第一次单击将起作用,第二次则不会。

I hope this much explaination will do :) 我希望这种解释可以做:)

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

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