我是js的新手,所以原諒我。我正在使用帶有js的html5音頻標籤來僅顯示播放和暫停按鈕。我想改變文字&暫停與圖像。像playbtn.png和pausebtn.png一樣。這是我卡住的地方。音頻使用js將圖片用於playpause btn
HTML :::
<!-- hidden audio player -->
<audio id="audio" controls autoplay hidden="">
<source src="music/eatForTwo.wav" type="audio/wav">
<source src="music/eatForTwo.mp3" type="audio/mpeg">
<p>Your Browser Doesn't Support The HTML5 audio Element</p>
</audio>
<button id="playpause" title="play" onclick="togglePlayPause()" ><img id="imgbtn" src="music/pausebtn.png"/></button>
<!-- javascript for audio control
-->
<script src="code/html5audio.js" type="text/javascript">
</script>
JS :::
// Grab a handle to the video
var audio = document.getElementById("audio");
// Turn off the default controls
audio.controls = false;
function togglePlayPause() {
var playpause = document.getElementById("playpause");
if (audio.paused || audio.ended) {
playpause.title = "pause";
playpause.style.backgroundImage = "url(music\pausebtn.png)";
audio.play();
}
else {
playpause.title = "play";
playpause.style.backgroundImage = "url(music\playbtn.png)";
audio.pause();
}
}
您已經有了按鈕?你想在按鈕上使用圖像而不是文本? – Sami
文本按鈕是原始設置。我想有2個按鈕圖像playbtn.png/pausebtn.png而不是文本更改。我對編程非常陌生 - (通過交易獲得信息保證)。 sudo代碼類曾經很多月前 - 所有的幫助表示讚賞! – user1790191
''這是您的代碼還是原創? – Sami