音乐播放器
var audio=document.createElement('audio');
console.log(audio);
audio.src = "music/ .mp3"
var objSpNum = document.getElementById("sp_num");
console.log(objSpNum);
// var currentNum = objSpNum.innerText; //表单标签
var currentNum=1;
console.log(currentNum);
window.onload = function() {
var objBtnPlay = document.getElementById("play");
var objBtnPause = document.getElementById("pause");
var objBtnPrev = document.getElementById("prev");
var objBtnNext = document.getElementById("next");
objBtnPlay.onclick = playMusic;
objBtnPause.onclick = pauseMusic;
objBtnPrev.onclick = prevMusic;
objBtnNext.onclick = nextMusic;
}
function playMusic(){
audio.play();
}
function pauseMusic(){
audio.pause();
}
/* function prevMusic(){
if(currentNum>1){
currentNum--;
}
audio.src="music/"+currentNum+".mp3";
console.log(audio.src);
objSpNum.innerText=currentNum;
}
function nextMusic(){
if(currentNum<3){
currentNum++;
}
audio.src="music/"+currentNum+".mp3";
console.log(audio.src);
objSpNum.innerText=currentNum;
} */
var a=["一支榴莲-海底", "买辣条也用券-起风了", "陈奕迅-孤勇者"]
function prevMusic(){
if(currentNum==1) {
currentNum=a.length;
}else{
currentNum--;
}
audio.src="music/"+currentNum+".mp3";
console.log(audio.src);
objSpNum.innerText=a[currentNum- 1];
playMusic();
}
function nextMusic(){
currentNum++;
if(currentNum>a.length) {
currentNum=1 ;
}
audio.src="music/"+currentNum + ".mp3";
console.log(audio.src);
objSpNum.innerText=a[currentNum- 1];
playMusic();
}