播放按钮点击一个蜂鸣声 [英] Play a beep sound on button click
问题描述
好吧,我在这里读了几答案,但他们并没有帮助我的人(其实,他们没有被接受的答案)
OK I've read several answers here but they didn't help me at all (in fact, none of them is being accepted as answer)
问题是如何在播放哔声 按钮,点击
我试图做一个网站,所以我想每个按钮的点击事件会起到蜂鸣声触摸屏设备上工作,这应该是对使用本网站的用户谁更好。蜂鸣声音文件是在这里: http://www.soundjay.com/button/beep-07 .WAV 。我只需要在谷歌浏览器(支持HTML5)
I am trying to make a website that works on touchscreen device so I want every button click events will play a beep sound, that should be nicer for users who using the website. Beep sound file is here: http://www.soundjay.com/button/beep-07.wav . I only need this work on Google Chrome (supports HTML5)
我明白这需要在客户端的工作,所以我尝试这样做:
I understand this need to work on client-side so I tried this:
使用Javascript:
Javascript:
<script>
function PlaySound(soundObj) {
var sound = document.getElementById(soundObj);
sound.Play();
}
</script>
HTML
<embed src="/beep.wav" autostart="false" type="audio/mpeg" loop="false" width="0" height="0" id="beep" enablejavascript="true" />
<asp:LinkButton ID="lbtnExit" runat="server" OnClick="lbtnExit_Click" OnClientClick="PlaySound('beep')" CssClass="btn btn-lg btn-danger" Text="Exit <i class='fa fa-sign-out' style='font-size: 40px'></i>"></asp:LinkButton>
但它不工作,没有任何反应,当我点击该按钮。
But it doesn't work, nothing happens when I click the button.
推荐答案
您可以使用音频标签是这样的:
You could use an audio tag like this:
<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>
下面是一个 Plunker
这篇关于播放按钮点击一个蜂鸣声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!