代码编辑器:
x
1
<p>点击按钮创建 AUDIO 元素, 一个将 preload 属性设置为 "none", 另外一个设置为 "auto"</p>
2
<button onclick="myFunction('none')">Audio 不使用 preload</button>
3
<button onclick="myFunction('auto')">Audio 使用 preload</button>
4
<br>
5
<script>
6
function myFunction(p){
7
var x = document.createElement("AUDIO");
8
x.setAttribute("controls", "controls");
9
var y = document.createElement("SOURCE");
10
y.setAttribute("src", "/static/i/html/horse.ogg");
11
y.setAttribute("type", "audio/ogg");
12
x.appendChild(y);
13
var z = document.createElement("SOURCE");
14
z.setAttribute("src", "/static/i/html/horse.mp3");
15
z.setAttribute("type", "audio/mpeg");
16
x.appendChild(z);
17
// 设置 preload 属性:
18
x.preload=p;