首页 文章 音乐播放器

音乐播放器

2022-04-23 13:24  浏览数:427  来源:1314520    

<script type="text/javascript" src="js/0 .js"></script>
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();
}



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)