案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<h3>演示如何创建 AUDIO 元素</h3>
6
7
<p>请点击按钮来创建 AUDIO 元素,该元素将播放 .ogg 文件格式的声音。</p>
8
9
<button onclick="myFunction()">试一下</button>
10
11
<p id="demo"></p>
12
13
<script>
14
function myFunction()
15
{
16
var x = document.createElement("AUDIO");
17
x.setAttribute("src", "/img/horse.mp3");
18
x.setAttribute("controls", "controls");
19
document.body.appendChild(x);
20
document.getElementById("demo").innerHTML = "<b>注释:</b>IE 和 Safari 不支持 .ogg 文件格式。这只是一个例子。如需使其在所有浏览器中运行,您应该在 audio 元素中使用 source 元素。";
21
}
22
</script>
23
24
</body>
25
</html>
26