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