<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>动态创建音频</title> </head> <body> <audio controls="controls" id="audio"> <source id="s1" src="music/qinshimoon.mp3"/> </audio> <input type="button" value="changeSource" onclick="changSource()"/> <script> function changSource() { var audio = document.getElementById("audio"); var src1 = document.getElementById("s1"); src1.src = "music/Heroeswithin.mp3"; audio.load(); } </script> </body> </html>
如果没有source标签,在audio中直接指定src内容,不需要load方法,改变src值,音频就会发生改变
时间: 2024-10-21 23:43:07