1.这段vue代码会播放声音,但是会有audio标签
<template><div><audio id="myAudio" controls><source src="./test.mp3" type="audio/mp3" />Your browser does not support the audio tag.</audio></div>
</template>
<script>
export default {mounted() {// 播放var audio = document.getElementById("myAudio");audio.play();}
}
</script>
2.只有不会显示video标签的播放
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Play MP3 on Button Click</title>
</head>
<body><button id="playButton">Play MP3</button>
<script>// 创建 Audio 对象const audio = new Audio('./test.mp3');// 获取按钮元素const playButton = document.getElementById('playButton');// 点击按钮时播放音频playButton.addEventListener('click', function() {audio.play();});
</script></body>
</html>