嗨,我想通過單擊功能以編程方式下載檔案。檔案存盤在公共檔案夾中,用戶反應路由器 Dom v6 但在互聯網上找不到任何幫助
uj5u.com熱心網友回復:
首先讓我糾正你。您想在單擊按鈕時下載檔案。
所以要做到這一點,你可以這樣做:
<button onClick={tempfunc}>Click me to Download File</button>
現在像這樣創建 tempfunc 函式:
function tempfunc(){
const filepath = "/logo512.png"; // Path of you file. Remember / points to public folder
const a = document.createElement('a');
a.href = filepath;
a.setAttribute("download","") // you can set name of you file to Download as. Like my file original name is logo512.png but if i want to download it as "somethis.png" then I will set download value (second Parameter) as "something.png"
a.click();
}
我希望這會對你有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/475760.html
標籤:javascript 反应 反应钩子 反应路由器 反应路由器dom
上一篇:我怎樣才能讓機器人回復dms
下一篇:使某些div消失的功能
