如何在html css中的复选框上播放声音


<audio id="myaudio" src="img/toggle.mp3" ></audio>
<div class="buttonpos">
<input class="toggle" onchange="myfunction" type="checkbox" id="switch">
<label onchange="document.getElementById('myaudio').play();" for="switch" class="switchLabel">
<span class="switchLabelBg"></span>
</label>
</div>

为什么这不起作用?当我点击复选框时,我正在尝试进行声音播放!

玩过之后,document.getElementById('myaudio').play();实际上应该在HTML中的另一个input标记中,所以如果您将HTML更改为它,应该可以工作:

<audio id="myaudio" src="img/toggle.mp3" ></audio>
<div class="buttonpos">
<input class="toggle" onchange="document.getElementById('myaudio').play();" type="checkbox" id="switch">
<label for="switch" class="switchLabel">
<span class="switchLabelBg"></span>
</label>
</div>

最新更新