基本上,我试图让歌曲名称显示在div名称“ musicText”中
<p id="musicText"></p>
<audio src="" controls id="audioPlayer">
Sorry, your browser doesn't support html5!
<ul id="playlist">
<li class="current-song"><a href="chrisbrown.mp3"></a>Chris Brown</li>
<li><a href="bmalone.mp3"></a>Bugzy Malone</li>
</ul>
</audio>
<script>
audioPlayer();
</script>
var currentSong = 0;
var currentSong = $("audio[name]")
$("#musicText").text(currentSong);
$("#audioPlayer")[0].src = $("#playlist li a")[0];
$("#audioPlayer")[0].play();
$("#playlist li a").click(function(e){
e.preventDefault();
$("#audioPlayer")[0].src = this;
$("#audioPlayer")[0].play();
$("#playlist li").removeClass("current-song");
currentSong = $(this).parent().index();
$(this).parent().addClass("current-song");
});
$("#audioPlayer")[0].addEventListener("ended", function(){
currentSong++;
if(currentSong == $("#playlist li a").length)
currentSong = 0;
$("#playlist li").removeClass("current-song");
$("#playlist li:eq("+currentSong+")").addClass("current-song");
$("#audioPlayer")[0].src = $("#playlist li a")[currentSong].href;
$("#audioPlayer")[0].play();
$('#musicText').append(currentSong);
$("#musicText").Text(currentSong);
});
}
此刻它会显示“ [object] [Object]”,我认为这是某种错误。
但是我非常希望第一首歌说“克里斯·布朗”,然后在完成时将“ musicText”更新为“ Bugzy Malone”
谢谢