猿问

js中function next()函数内的参数运算后值无法改变

var music=["m1","m2","m3","m4","m5","m6","m7","m8","m9","m10"];
var i=0;
function next(){
	i=i+1;
	if(i=music.length){
		i=0;
	}
	console.log(music.length);
	console.log(i);
	console.log(music[i]);
	var mp3=document.getElementById(music[i]);
	mp3.play();
	isplay=true;
	document.getElementById("center").className="pause";
}
为何next()里面的i自增1不起作用,i的值还是0???


冰山点水
浏览 1582回答 1
1回答

刚毅87

 if(i=music.length){         i=0;     }if 判断条件写错了,应该为 i==music.length
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答