[英]Add sound through onclick-event button
Trying to add sound to these buttons 尝试向这些按钮添加声音
<a href="stout_page.html"><audio id="sound1" src="Button_Push.mp3" preload="auto"></audio><button onClick="document.getElementId('sound1').play();" target="_top">Stouts</button></a>
<a href="sours_page.html"><button target="_top">Sours</button></a>
<a href="ipa_page.html"><button target="_top">India Pale Ales</button>. </a>
<a href="brett and more.html"><button target="_top">Brett and more</button></a>
<a href="test_page.html"><button target="_top">test</button></a>
you can add sounds to button but it will refresh page as you are using href
on click of a
tag. 你可以添加声音到按钮,但是当你使用它会刷新页面href
上点击a
标签。 inside that button
click will call play function to play the sound. 在该button
单击将调用播放功能以播放声音。
<script>
function play(src) {
var player = document.getElementById('audio');
player.pause();
player.currentTime = 0;
player.src = src;
player.play();
}
</script>
<input type="button" value="PLAY" onclick="play('http://dev.interactive-creation-works.net/1/1.ogg')">
<audio id="audio" src="http://dev.interactive-creation-works.net/1/1.ogg" autostart="false"></audio>
<a href="stout_page.html"><audio id="sound1" src="Button_Push.mp3" preload="auto"></audio>
<button onClick="play('Button_Push.mp3');" target="_top">Stouts</button></a>
<a href="sours_page.html"><button target="_top" onClick="play('Button_Push-1.mp3');" >Sours</button></a>
<a href="ipa_page.html"><button target="_top" onClick="play('Button_Push-2.mp3');">India Pale Ales</button></a>
<a href="brett and more.html"><button target="_top" onClick="play('Button_Push-3.mp3');">Brett and more</button></a>
<a href="test_page.html"><button target="_top" onClick="play('Button_Push-4.mp3');">test</button></a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.