DominicWoo(讨论 | 贡献) |
DominicWoo(讨论 | 贡献) |
||
第9行: | 第9行: | ||
a.src = link; | a.src = link; | ||
audio.append(a); | audio.append(a); | ||
+ | console.log(a); | ||
var button = document.createElement('button'); | var button = document.createElement('button'); | ||
button.onclick = function(){ | button.onclick = function(){ | ||
− | console.log(a) | + | console.log(button); |
+ | console.log(a); | ||
if (a.paused){ | if (a.paused){ | ||
a.play(); | a.play(); |
2021年2月4日 (四) 04:06的版本
/* 这里的任何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); console.log(a); var button = document.createElement('button'); button.onclick = function(){ console.log(button); console.log(a); if (a.paused){ a.play(); button.classList.add('audio-player-playing'); button.classList.remove('audio-player-paused'); }else{ a.pause(); button.classList.add('audio-player-paused'); button.classList.remove('audio-player-playing'); }; }; a.onended = function(){ button.classList.remove('audio-player-playing'); }; audio.append(button); }; })();