播放暂停html5

时间:2014-06-20 21:49:08

标签: javascript html5 video

我试图创建一个按钮来暂停和播放视频,并在点击时更改innerHTML。这是我尝试过的,我无法理解它为什么不起作用。任何人都可以帮忙:

function play() {
  var video = document.getElementById("video1");
  video.play();
}

var playButton = document.getElementById("play-pause");

playButton.addEventListener("click", function () {

    if (video.paused === true) {
        // Play the video
        video.play();

        // Update the button text to 'Pause'
        playButton.innerHTML = "Pause";
    } else {
        // Pause the video
        video.pause();

        // Update the button text to 'Play'
        playButton.innerHTML = "Play";
    }
});

1 个答案:

答案 0 :(得分:0)

var video = document.getElementById("video1");
var playButton = document.getElementById("play-pause");

playButton.addEventListener("click", function () {

    if (video.paused === true) {

        video.play();
        playButton.innerHTML = "Pause";

    } else {

        video.pause();
        playButton.innerHTML = "Play";
    }
});