2017-07-19 48 views
-2

任何人都可以在这里帮助我,因为我不太清楚问题是什么,我认为这与放置其中一个线。需要帮助,因为按按钮HTML/Javascript时声音不会播放

https://jsfiddle.net/70kwwpqp/

<div class="animatedButton"> 

    <audio id="Sound" src="Sounds/beep.mp3"> </audio> 

    <a href="Home.html"> 
    <button class="aButton" <onclick="playBeep()"> <img src="img/Home.png"> </button> 
    </a> 

    </div> 

function playBeep() 
{ 

var sound = document.getElementById("aButton") 
sound.play() 

} 
+1

您分配了 'A按钮' 作为个按钮的类。另外一个错字' OneNeptune

+0

链接内不允许使用按钮。见https://stackoverflow.com/questions/6393827/can-i-nest-a-button-element-inside-an-a-using-html5 –

+0

'aButton'是一个班级,你正在使用'getElementById' – Nihal

回答

0

你有一个语法错误和突出的jsfiddle为你。 onclick之前不应该有<

此外,你得到button并要求它play()。您应该通过编号Sound获取音频元素并播放该元素。

+0

我已经做到了,但我仍然得到一个错误 playBeep未定义在HTMLButtonElement.onclick –

+0

更新与另一个问题,你可能需要修复。如果还有更多的话。 @ CaseyKusella-Gussin – mintychai

1

<audio id="audio" src="http://www.soundjay.com/button/beep-07.wav" autostart="false" ></audio> 
 
    <a onclick="playSound();"> Play</a> 
 
    <script> 
 
    function playSound() { 
 
      var sound = document.getElementById("audio"); 
 
      sound.play(); 
 
     } 
 
    </script>

+0

其他人都说过,尽管一言为蔽,但没有其他工作。 我现在得到的错误:playBeep没有在HTMLButtonElement.onclick 定义你能帮我吗? –

+0

在src中尝试不同的声音 – Nihal

+0

这是因为他们将函数名称更改为“playSound()”。这是你的问题吗? – mintychai