大家晚上好。每当我点击对象时,我都会尝试添加声音效果。我想在javascript向用户显示消息的同时添加声音。我怎么做 ?
这里的HTML代码:
<audio id="music" preload="auto">
<source src="sounds/backgroundMusic.mp3" type="audio/mp3">
<source src="sounds/backgroundMusic3.mp3" type="audio/mp3">
<source src="sounds/sound1.mp3" type="audio/mp3">
</audio>
** Script.js * here:*
if(gameData.opendCardsNumber > 0 && gameData.opendCardsNumber < 10)
{
for(var i = 0; i <= 5; i++)
{
var randomString = Math.floor(Math.random() * messages.length);
var randomStringElement = messages[randomString];
$("#messageBox").html(randomStringElement);
}
}