【发布时间】:2019-07-08 08:42:45
【问题描述】:
您好,我想知道如何从 button onclick 事件中调用 a 点击:
到目前为止,我已经通过这两种方法使它起作用了:
<a class="button" type="application/octet-stream" href="http://localhost:5300/File" download>Click here for dld</a>
<input type="button" onclick="location.href='http://localhost:5300/File';" value="Download"/>
但我不能让它与 js 一起工作;我试过这样:
<button onclick="Save('http://localhost:5300/File')">Download</button>
function Save(url){
var link=document.createElement('a');
link.url=url;
link.name="Download";
link.type="application/octet-stream";
document.body.append(link);
link.click();
document.body.removeChild(link);
delete link;
}
P.S我需要使用<button></button>而不是input!
【问题讨论】:
-
应该是
link.href
标签: javascript download href