我很遺憾地一直no html到所以我希望你能回答我的問題。試圖在網頁上實現兩個音頻文件
我試圖在我的網頁上實現三個音頻文件,但只有一個源文件正在播放。其他文件的按鈕有效,但它們只能從一個源文件播放。你可以幫我嗎?
下面的代碼:
<div class="sound1">
<div style="text-align:center; width:100px; height:100px; margin-left:390px; margin-top:0px; background-repeat:no-repeat; ">
<button style="background-image:url(speaker_bakur.png); width:100px; height:100px; border:transparent;
; "margin-top:0px; margin-left:0px;" onclick="playPause();" ></button>
<audio id="Sound">
<source src="" type="audio/wav" />
<source src="" type="audio/ogg" />
<source src="svartbakur-4.mp3" type="audio/mpeg" />
</audio>
</div>
<script type="text/javascript">
var myAudio=document.getElementById("Sound");
function playPause()
{
if (myAudio.paused)
myAudio.play();
else
myAudio.pause();
}
</script>
</div>
</div><!--Div hyphenate-->
<div class="sound2">
<div style="text-align:center; width:100px; height:100px; margin-left:390px; margin-top:0px; background-repeat:no-repeat; ">
<button style="background-image:url(speaker_likka.png); width:100px; height:100px; border:transparent;
; "margin-top:0px; margin-left:0px;" onclick="playPause();" ></button>
<audio id="Sound">
<source src="" type="audio/wav" />
<source src="" type="audio/ogg" />
<source src="likka-6.mp3" type="audio/mpeg" />
</audio>
</div>
<script type="text/javascript">
var myAudio=document.getElementById("Sound");
function playPause()
{
if (myAudio.paused)
myAudio.play();
else
myAudio.pause();
}
</script>
</div>
</div><!--Div hyphenate-->
<div class="sound3">
<div style="text-align:center; width:100px; height:100px; margin-left:390px; margin-top:0px; background-repeat:no-repeat; ">
<button style="background-image:url(speaker_fiskimasi.png); width:100px; height:100px; border:transparent;
; "margin-top:0px; margin-left:0px;" onclick="playPause();" ></button>
<audio id="Sound">
<source src="" type="audio/wav" />
<source src="" type="audio/ogg" />
<source src="fiskimasi-21.mp3" type="audio/mpeg" />
</audio>
</div>
<script type="text/javascript">
var myAudio=document.getElementById("Sound");
function playPause()
{
if (myAudio.paused)
myAudio.play();
else
myAudio.pause();
}
</script>
</div>
</div><!--Div hyphenate-->
太謝謝你了!
您需要定義其他兩個源標籤的源文件的位置。 '' –
閱讀此以獲取更多信息。 http://net.tutsplus.com/tutorials/html-css-techniques/quick-tip-the-html-5-audio-element/ –
您的按鈕樣式存在錯誤。刪除額外;和「 – Timbadu