2012-11-03 18 views
0

我是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(); 
} 
} 
+0

您已經有了按鈕?你想在按鈕上使用圖像而不是文本? – Sami

+0

文本按鈕是原始設置。我想有2個按鈕圖像playbtn.png/pausebtn.png而不是文本更改。我對編程非常陌生 - (通過交易獲得信息保證)。 sudo代碼類曾經很多月前 - 所有的幫助表示讚賞! – user1790191

+0

''這是您的代碼還是原創? – Sami

回答

0

編輯您的js如下,但是你必須改變url(c:\folder\img.jpg)url(yourPath) ....現在yourPath並不意味着yourPath它表示圖像在硬盤上的位置

// 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(c:\folder\img.jpg)"; 
    audio.play(); 
} 
else { 
    //playpause.title = "play"; 
    playpause.style.backgroundImage = "url(c:\img1.jpg)"; 
    audio.pause(); 
} 
+0

@ user1790191查看編輯答案。我只是改變了你的js中的幾行。你可以比較你和我的。我仍然在那裏。嘗試快速回應:) – Sami

+0

@ user1790191實際上,新用戶在SO上折舊。這也許是政策。他們被忽略,因爲他們通常無法得到所講的內容,而他們的問題通常不會引起太多的讚揚。但對我而言,他們應得的最多。你知道我正在自願花時間。其實它的facebook對我來說:)你的問題仍然存在? – Sami

+0

@ user1790191更改''to'