我无法让我的代码在点击图片时播放音频文件。 我尝试过不同的文件类型,但不会改变任何内容。
这是我正在使用的代码:
http://jsfiddle.net/adamsears/kZF9T/
<a onclick="playSounds()">
<img src="http://us.123rf.com/400wm/400/400/natis76/natis761205/natis76120500079/13695359-speaker-icon.jpg" width="300px" height="300px" id="ImageButton1">
var sounds = [
"http://adambencreative.co.uk/wp-content/uploads/2013/12/test.mp3",
"http://adambencreative.co.uk/wp-content/uploads/2013/12/test2.mp3",
],
oldSounds = [];
var playSounds = function () {
var index = Math.floor(Math.random() * (sounds.length)),
thisSound = sounds[index];
oldSounds.push(thisSound);
sounds.splice(index, 1);
if (sounds.length < 1) {
sounds = oldSounds.splice(0, oldSounds.length);
}
$("#element").html("<audio autoplay><source src=\"" + thisSound + "\" type=\"audio\/mp3\"><\/audio>");
}
有谁知道如何让它在手机/平板电脑上工作?