Javascript HTML5在点击移动设备上播放音频文件
我正在尝试获取一个音频文件,以便在单击时播放。我使用的代码在浏览器中运行良好,但在任何移动设备上似乎都不起作用。有什么我遗漏的吗Javascript HTML5在点击移动设备上播放音频文件,javascript,html,audio,mobile,onclick,Javascript,Html,Audio,Mobile,Onclick,我正在尝试获取一个音频文件,以便在单击时播放。我使用的代码在浏览器中运行良好,但在任何移动设备上似乎都不起作用。有什么我遗漏的吗 <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css"> <script src="script.js"></script> </head> <body>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<audio id="audio" src="http://ricklemon.co.uk/game/sound.ogg" autostart="false" ></audio>
<a onclick="PlaySound()"><img src="http://ricklemon.co.uk/game/images/speaker.png" width="200px" /></a>
<script>
function PlaySound() {
var sound = document.getElementById("audio");
sound.play()
}
</script>
</body>
</html>
函数PlaySound(){
var sound=document.getElementById(“音频”);
播放
}
您的问题是,ogg音频文件在windows phone和ios上都无法工作,因此您应该添加另一个扩展名为.mp3的文件才能工作您还需要另一个声音扩展名(例如mp3/mpeg)可能与