課程
/前端開發
/JavaScript
/JavaScript進階篇
不太明白 為啥要循環兩次。。
2015-08-21
源自:JavaScript進階篇 10-1
正在回答
?for(var i=0; i<aIl.length;i++){
? ? ? ? ? ? ? ? aIl[i].index = i;
? ? ? ? ? ? ? ? aIl[i].onclick = function(){
? ? ? ? ? ? ? ? ? ? change(this.index);
? ? ? ? ? ? ? ? ? ? iNow = this.index;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ?}
? ? ? ? ? ? ?function change(iNow){
? ? ? ? ? ? ? ? for(var i=0; i<aIl.length;i++){
? ? ? ? ? ? ? ? ? ? aIl[i].className = "";
? ? ? ? ? ? ? ? ? ? aDiv[i].style.display = "none";
? ? ? ? ? ? ? ? ? ? aSpan[i].className = "";
? ? ? ? ? ? ? ? }?
? ? ? ? ? ?
第一次循環是:循環所有的li ?加點擊事件?
第二次循環是:循環所有的li 并且清空他們當前樣式
我可能說的不是很具體,希望您能理解!
舉報
本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界
2 回答for循環
2 回答FOR循環
3 回答for 循環
3 回答for循環
1 回答for循環
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-08-24
?for(var i=0; i<aIl.length;i++){
? ? ? ? ? ? ? ? aIl[i].index = i;
? ? ? ? ? ? ? ? aIl[i].onclick = function(){
? ? ? ? ? ? ? ? ? ? change(this.index);
? ? ? ? ? ? ? ? ? ? iNow = this.index;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ?}
? ? ? ? ? ? ?function change(iNow){
? ? ? ? ? ? ? ? for(var i=0; i<aIl.length;i++){
? ? ? ? ? ? ? ? ? ? aIl[i].className = "";
? ? ? ? ? ? ? ? ? ? aDiv[i].style.display = "none";
? ? ? ? ? ? ? ? ? ? aSpan[i].className = "";
? ? ? ? ? ? ? ? }?
? ? ? ? ? ?
第一次循環是:循環所有的li ?加點擊事件?
第二次循環是:循環所有的li 并且清空他們當前樣式
我可能說的不是很具體,希望您能理解!