javascript 创建video元素

<!DOCTYPE html>
<html>
<body>

<h3>演示如何创建 VIDEO 元素</h3>

<p>请点击按钮来创建 VIDEO 元素,该元素将播放 .ogg 文件格式的影片。</p>

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

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

<script>
function myFunction()
{
var x = document.createElement("VIDEO");
x.setAttribute("width", "320");
x.setAttribute("height", "240");
x.setAttribute("controls", "controls");
x.setAttribute("src", "/i/movie.ogg");
document.body.appendChild(x);
document.getElementById("demo").innerHTML = "<b>注释:</b>IE 和 Safari 不支持 .ogg 文件格式。这只是一个例子。如需使其在所有浏览器中运行,您应该在 video 元素中使用 source 元素。";
}
</script>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/10551415.html