我试图创建一个按钮来暂停和播放视频,并在点击时更改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";
}
});
答案 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";
}
});