DominicWoo(讨论 | 贡献) |
DominicWoo(讨论 | 贡献) |
||
第12行: | 第12行: | ||
button.onclick = function(){ | button.onclick = function(){ | ||
var audio = this.parentNode; | var audio = this.parentNode; | ||
− | + | var a = audio.children[0]; | |
if (a.paused){ | if (a.paused){ | ||
a.play(); | a.play(); | ||
− | + | this.classList.add('audio-player-playing'); | |
− | + | this.classList.remove('audio-player-paused'); | |
}else{ | }else{ | ||
a.pause(); | a.pause(); | ||
− | + | this.classList.add('audio-player-paused'); | |
− | + | this.classList.remove('audio-player-playing'); | |
}; | }; | ||
}; | }; | ||
a.onended = function(){ | a.onended = function(){ | ||
− | + | this.parentNode.children[1].classList.remove('audio-player-playing'); | |
}; | }; | ||
2021年2月4日 (四) 04:26的版本
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */ (function(){ var audios = document.getElementsByClassName("audio-player"); for(var i=0;i<audios.length;i++){ var audio = audios[i]; var link = audio.firstElementChild.href; audio.innerHTML = ""; var a = document.createElement('audio'); a.src = link; audio.append(a); var button = document.createElement('button'); button.onclick = function(){ var audio = this.parentNode; var a = audio.children[0]; if (a.paused){ a.play(); this.classList.add('audio-player-playing'); this.classList.remove('audio-player-paused'); }else{ a.pause(); this.classList.add('audio-player-paused'); this.classList.remove('audio-player-playing'); }; }; a.onended = function(){ this.parentNode.children[1].classList.remove('audio-player-playing'); }; audio.append(button); }; })();