<html>
<body>
<p>点击按钮创建 VIDEO 元素,一个设置 autoplay 属性为 true, 另一个设置 autoplay 属性为 false。</p>
<button onclick="myFunction(true)">Video 使用自动播放</button>
<button onclick="myFunction(false)">Video 不使用自动播放</button>
<br>
<script>
function myFunction(p)
{
var x = document.createElement("VIDEO");
x.setAttribute("id", "myVideo");
x.setAttribute("controls", "controls");
var y = document.createElement("SOURCE");
y.setAttribute("src", "movie.mp4");
y.setAttribute("type", "video/mp4");
x.appendChild(y);
var z = document.createElement("SOURCE");
z.setAttribute("src", "movie.ogg");
z.setAttribute("type", "video/ogg");
x.appendChild(z);
// Set the autoplay property:
x.autoplay=p;
document.body.appendChild(x);
}
</script>
</body>
</html>