单击时如何制作播放音频的图像

时间:2015-10-18 21:35:14

标签: html image button audio

我正在尝试实现播放音频的按钮。我不想要滑块。

有没有摆脱滑块,或者可能使用按钮的图像?

当前代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Music</title>
<style type="text/css">
body {
        color:transparent;
}
</style>
</head>

<body onLoad="RandomSong();">
<audio id="content" src="background1.mp3" controls></audio>

<script>
function RandomSong() {
    var Music = ["background1.mp3","background2.mp3","background3.mp3","background4.mp3","background5.mp3"];
    var randomCode = Math.floor(Math.random()*Music.length);
    document.getElementById("content").value = "mp3=" + Music[randomCode] + "&amp;showslider=0&amp;width=5&amp;loop=1&amp;autoplay=0&amp;volume=50";
}
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

有一个简单的JQuery解决方案:

<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$('#track1').click(function(){
   $('#wrap').append('<embed id="embed_player" src="audio.wav" autostart="true" hidden="true"></embed>');
});
});
</script>
<img name="track1" src="images/track1.png" width="180" height="180" border="0" id="track1" alt="" />
<div id="wrap">&nbsp;</div>

Src:从@blasteralfred的回答中查看这篇类似的帖子:Play sound file when image is clicked