<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="download()">下载</button>
<script>
function downloadMp3(filePath) {
fetch(filePath).then(res => res.blob()).then(blob => {
const a = document.createElement('a');
document.body.appendChild(a)
a.style.display = 'none'
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = 'xxxx.mp3';
a.click();
document.body.removeChild(a)
window.URL.revokeObjectURL(url);
});
}
function download() {
this.downloadMp3('http://m10.music.126.net/20210830153737/455ba93f37a9ece83265d4cc72b0b99b/yyaac/obj/wonDkMOGw6XDiTHCmMOi/3064996091/2230/481a/669f/ea996fd708b9cbb995e5dfb5b27295c1.m4a');
}
</script>
</body>
</html>
js 实现下载音频
最新推荐文章于 2024-06-24 18:43:19 发布