根据媒体是正在播放还是暂停来更改按钮的文本

Changing the text of a button according to whether media is playing or paused?

本文关键字:按钮 暂停 文本 媒体 播放      更新时间:2023-09-26

我的代码部分工作。当我单击播放时,它会变为暂停,但是当我单击暂停后,它只是保持暂停并且不会变回播放?

var playOrPause = function (id, button) {
var pp = document.getElementById(id);
    if(pp.paused) {
        button.textContent = 'Play';
    } else if(!pp.paused) {
        button.textContent = 'Pause';
    }
};

刚刚弄清楚了我的问题。我编写了一个错误的事件侦听器,哈哈谢谢你们的帮助!!

$('.player_audio').click(function() {if (this.paused == false) { this.pause();
  alert('music paused'); } else { this.play();alert('music playing');}});

这将帮助你