[英]play an audio file once
is there a way to play a mp3/wav file in html only once if the condition is met. 如果满足条件,有没有办法只播放一次html中的mp3 / wav文件。 I am trying to do but the mp3 file is not playing after my required condition is met..
我正在尝试这样做,但是在满足我的要求的条件后mp3文件没有播放。
<input type="text" id="question"/>
<audio src="one.mp3" id="one" preload="auto"></audio>
<input type="text" id="question1"/>
<audio src="two.mp3" id="two" preload="auto"></audio>
<script>
$("#question").blur(function() {
if ($(this).val() == 'Paris') {
document.getElementById("one").play();
}
});
$("#question1").blur(function() {
if ($(this).val() == 'France') {
document.getElementById("two").play();
}
});
</script>
Assuming that your condition is truly met, there are a few reasons why you might not be able to hear your sound play: 假设您的条件确实得到满足,则可能由于以下原因您可能听不到声音播放:
MP3
). MP3
)。 source
as shown in the example . source
,如示例所示。 src
attribute (in this case, ./one.mp3
or ./two.mp3
). src
属性(在本例中为./one.mp3
或./two.mp3
)进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.