我有一个带有图像的div。在悬停此图像时,我想要播放一个音频,然后点击相同的图像我想要播放另一个音频。这是我的代码到目前为止,似乎没有用?有任何想法吗?感谢
<div id="one">
<img src="lib/images/check-mark-32.png" alt=""/></div>
<audio id="sound-1a">
<source src="lib/sound/01 partitano.1.mp3"></source>
<source src="lib/sound/01 partitano.1.ogg"></source>
Your browser isn't invited for super fun audio time.
</audio>
<audio id="sound-1">
<source src="lib/sound/01 Solo Piano - 1 - Metamorphosis.mp3"></source>
<source src="lib/sound/01_Solo_Piano_1_Metamorphosis.ogg"></source>
Your browser isn't invited for super fun audio time.
</audio>
<script>
var audio = $("#sound-1a")[0];
$("#one").mouseenter(function() {
audio.play();
});
var audio = $("#sound-1")[0];
$("#one").click(function() {
audio.play();
});
</script>
答案 0 :(得分:1)
试试这个
$("#one").mouseenter(function () {
$('#sound-1a').get(0).play();
});
$("#one").click(function () {
$('#sound-1').get(0).play();
});