首頁 文章 音乐播放器

音乐播放器

2022-04-23 13:24  瀏覽數:431  來源: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)