<body>
<section>
<p>
<input type="button" name="htmlName" id="littleButton" value="点击我下载文件" onclick="downloadFile()">
</p>
<p>
<a href='/files/Test2.png' download="Test2.png">点击我下载文件</a>
</p>
</section>
</body>
<script>
/*let fileUrl="file:///D:\\files\\Test2.png";*/
let fileUrl="/files/Test2.png";
function downloadFile1() {
window.location.href = fileUrl;
}
function downloadFile() {
//Will take you to BaiDu.
window.location.href ='/files/Test2.png';
}
</script>
</html>
第一种可以调到映射的链接,第二种用script却不行
记得清除缓存