-
<video>标记语法格式如下。
<video src="url" controls="controls">替代文字</video>
属性 | 值 | 说明 |
src | url | 要播放视频的URL |
controls | controls | 添加播放、暂停和音量等控件 |
<video width="320px" height="240px" controls="controls"> <source src="movie.ogg" type="video/ogg"/> <source src="movie.mp4" type="video/mp4"/> <source src="movie.webm" type="video/webm"/>
您的浏览器不支持video标记
</video>
play() | 播放媒体,paused属性的值自动修改为false |
pause() | 暂停媒体,paused属性的值自动修改为true |
<video id="myVideo" width="320" height="240" controls> <source src="images/lego.ogv" type="video/ogv"> <source src="images/lego.mp4" type="video/mp4"> <source src="images/lego.webm" type="video/webm"> <object data=" images/lego.mp4" width="320" height=“240”> <embed width="320" height="240" src=" images/lego.swf"> </object> </video>
<br>
<button onClick="document.getElementById('myVideo').play()">播放</button> <button onClick="document.getElementById('myVideo').pause()">暂停</button> <button onClick="document.getElementById('myVideo').volume += 0.1">音量+</button> <button onClick="document.getElementById('myVideo').volume -= 0.1">音量-</button> <button onClick="document.getElementById('myVideo').muted = true"> 静音</button> <button onClick="document.getElementById('myVideo').muted = false">取消静音</button>