【发布时间】:2015-12-02 17:54:04
【问题描述】:
为了我的大学工作,我必须制作视频控件,并且我正在尝试实现一个播放/暂停按钮以开始,但它不起作用。这是我的代码:
HTML:
<script src="Scripts/VideoScript.js"></script>
<section id="Example_Video_Container">
<video width = 576 height = 432 id = "Example_Video">
<source src="Videos/Example_Video.mp4">
<source src="Videos/Example_Video.webm">
</video>
<div id="Example_Video_Controls">
<button type="button" id="Play_Pause" >Play</button>
</div>
</section>
JavaScript:
window.addEventListener (“DOMContentLoaded”,handleWindowLoad)
function handleWindowLoad ()
{
var Video = document.getElementById ( "Example_Video" );
var PlayButton = document.getElementById ( "Play_Pause" );
var MuteButton = document.getElementById ( "Mute_Unmute" );
var Slider = document.getElementById ( "Slider" );
PlayButton.addEventListener ( "click", Play_Pause_Video ) ;
function Play_Pause_Video ()
{
if (Video.paused === true)
{
Video.play();
PlayButton.innerHTML = "Pause";
}
else
{
Video.pause();
PlayButton.innerHTML = "Play";
}
}
}
我也检查了我的文件路径,应该没问题。
【问题讨论】:
-
html5 video 标签提供了它自己的控件。
<video width = 576 height = 432 id = "Example_Video" controls> -
注意
window.addEventListener (“DOMContentLoaded”,handleWindowLoad)中的“。它不是 javascript 识别的实际"。将其替换为"。 -
请看我的回答@Will
-
谢谢,我试过了,效果也很好,很容易解决谢谢
标签: javascript html