【发布时间】:2014-05-16 03:06:05
【问题描述】:
我想在下面的脚本中使用 class 而不是 id.... 我想要一个 mp3 列表,每个都有对应的按钮,但是当我点击任何播放按钮时,它会播放第一个 mp3。
<!DOCTYPE html>
<html>
<body>
<button onclick="playVid()" type="button">Play</button>
<audio controls id="video1" style="display: none;">
<source src="http://localhost/astrorecords/wp-content/uploads/2014/05/280.mp3" type="audio/mp3">
</audio>
<script>
var myVideo=document.getElementById("video1");
function playVid() {
myVideo.play();
var obj = document.getElementById("video1");
if (obj) {
obj.style.display='block';
}
}
</script>
</body>
</html>
【问题讨论】:
-
查询类无法实现您要的解决方案,您更感兴趣的是上下文以及作用于(点击)的元素。
标签: javascript jquery html audio