大家好!
我这里有问题
我有3个
<a href="{$baseUrl}/default/report/download-ready-prompt?id={$order.id}" name ="ahref" id="promptButton" class="button-blue printing">Prompt</a>
<a href="{$baseUrl}/default/report/download-ready-cert?id={$order.id}" name = "ahref" id="certButton" class="button-blue printing withSignature">Cert</a>
<a href="{$baseUrl}/default/report/download-ready-invoice?id={$order.id}" name ="ahref" id="invoiceButton" class="button-blue printing withSignature">Invoice</a>
这 3 个链接在同一页面加载
如果单击一个链接,它将下载。 但如果我再次点击它,我将不会下载
因为我输入了这样的 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>
如果我想下载两次但我会阻止重复提交,我的代码是什么? 任何人都可以帮助我请:(
最佳答案
此示例代码可能有助于解决您的问题。
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:
$('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');
}
});
关于javascript - 如何防止重复提交 <a href>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15402241/