【发布时间】:2016-05-16 01:57:25
【问题描述】:
我被困住了。我有两个按钮,每个按钮都有一个功能,一个在单击时播放声音,一个在单击时暂停声音。我希望能够在它们之间切换,所以当它关闭时我只看到一个按钮说“声音开启”,反之亦然。 问题是:我的 Javascript 知识!
<audio id="spacesound"> </audio>
<button type="button" id="offbutton" class="offbutton" onclick="disableSound()">Sound off</button><br>
<button type="button" id="onbutton" class="onbutton" onclick="reenableSound()">Sound on</button>
这些是按钮,如果需要,它们是它们调用的函数。
//it plays on auto when the page is loaded
myAudiothree = new Audio('media/deepspace.mp3');
myAudiothree.loop = true;
myAudiothree.play();
//continue sound
function reenableSound()
{
myAudiothree.play();
}
//pause sound
function disableSound()
{
myAudiothree.pause();
}
可能有一些 CSS 代码,但我更愿意在 JS 中使用它,谢谢!
【问题讨论】:
标签: javascript jquery html