html < a href="javascript:void(0);" download>下载< /a>停止下载

col17t5w  于 2023-05-27  发布在  Java
关注(0)|答案(4)|浏览(202)

我的问题是当<a>标签没有链接,所以如何停止下载时,点击链接

例如:我的链接在下面

<a href="javascript:void(0);" download>download</a>

所以当我点击下面链接下载一个void(0)文件
但我想停止下载时,<a>标签哈没有链接和href=javascript:void(0)

gj3fmq9x

gj3fmq9x1#

写一个click事件处理器,防止像下面这样的默认事件,

$('a#id-of-it').on('click', function(event) {
  // Do whatever you want
  event.preventDefault();
})

html看起来像

<a href="#" id="id-of-it">Download</a>
gojuced7

gojuced72#

从标签中删除下载属性

<a href="javascript:void(0);" class="classname">download</a>

或者你可以使用jquery

$('tag.classname').on('click', function(e) {
  e.preventDefault();
  //this stop default prevent or action
  or you can use 
  e.stopPropagation();
})
$('a.demo').click(function(e) {
      e.preventDefault();
      //this stop default prevent or action
      //or you can use 
      e.stopPropagation();
 })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0);" class="demo" download>download</a>

或者使用javascript

document.getElementById("demo").addEventListener("click", function(e){
    e.preventDefault()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0);" id="demo" download>download</a>
cbwuti44

cbwuti443#

是的,我已经解决了<?php condition的问题
如果变量没有值,则创建不带download选项<a>标记,如果变量有值,则创建带下载的<a>标记

u0njafvf

u0njafvf4#

$('a.demo').click(function(e) {
      e.preventDefault();
      //this stop default prevent or action
      //or you can use 
      e.stopPropagation();
 })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="javascript:void(0);" class="demo" download>download</a>

相关问题