您好,欢迎来到外链网!
当前位置:外链网 » 站长资讯 » 专业问答 » 文章详细 订阅RssFeed

html a标签点击事件,点击a标签触发onclick事件

来源:互联网 浏览:52次 时间:2023-04-08

a标签

<a></a>

a标签下载文件

<a download="filename" id="a_downloadPdf" rel="external nofollow" rel="external nofollow" href="文件地址">点击下载</a>

添加点击事件

<a download="filename" id="a_downloadPdf" rel="external nofollow" rel="external nofollow" href="文件地址" οnclick="click()">点击下载</a>

因为 点击事件先于href执行 当点击事件返回true时 href执行 返回false href不执行

function click() { $.ajax({ type: "get", url: "url", dateType: "json", //data: "", success: function (data) { if (data.status == 1) { return true; } }, error: function () { return false; }, async: false });}

因为需要ajax执行完毕后再执行href 所以需要设置为同步请求async: false 保证文件下载时已经生成 如果async: true 文件还没有生成就已经执行下载?

24739216