代码示例:(标识:htmldom_source_create)
<!DOCTYPE html>
<html>
<body>

<p>单击按钮可创建 SOURCE 元素,并将它们附加到 AUDIO 元素。</p>

<audio controls id="myAudio" autoplay>
Your browser does not support the audio tag.
</audio><br>

<p id="demo"></p>

<button onclick="myFunction()">试一试</button>

<script>
function myFunction() {
  var x = document.createElement("SOURCE");
  x.setAttribute("src", "/static/demo/video/song.mp3");
  x.setAttribute("type", "audio/mpeg");
  document.getElementById("myAudio").appendChild(x);

  document.getElementById("demo").innerHTML = "音频播放器现在可以正常工作了。按播放键可听到音乐。";
}
</script>

</body>
</html>
运行结果: