課程
/前端開(kāi)發(fā)
/jQuery
/jQuery基礎(chǔ)(二)—DOM篇
DOM篇最后一節(jié),怎么用each()方法逐個(gè)使每個(gè)li改變顏色?
2016-10-30
源自:jQuery基礎(chǔ)(二)—DOM篇 6-10
正在回答
????<script?type="text/javascript"> ????i?=?0; ????$("button:last").click(function()?{ ????????$("li").each(function(index,?element)?{???????? ????????????if?(index?==?i)?{ ????????????????$(this).css('color','blue'); ????????????} ????????}); ????????i++; ????}) ????</script>
?i = 0;
? ? $("button:last").click(function() {
? ? ? ? $("li").each(function(index, element) { ? ? ? ?
? ? ? ? ? ? if (index == i) {
? ? ? ? ? ? ? ? $(this).css('color','blue');
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? i++;
? ? })
思路就是加個(gè)定時(shí)器,延時(shí)變色。比如第1個(gè)li過(guò)200毫秒變成紅色,第2個(gè)li過(guò)400毫秒再變成紅色...
var?interval?=?0; $("li").each(function(index,?element)?{ ????var?$el?=?$(this); ????setTimeout(function()?{ ????????$el.css('color','red'); ????},?interval?+=?200); });
慕粉198531 提問(wèn)者
舉報(bào)
jQuery第二階段開(kāi)啟DOM修煉,了解創(chuàng)建、插入、刪除與替換
2 回答each方法用的多嗎
5 回答$("li").css('')和$("li").each有什么區(qū)別嗎?
4 回答each方法中element參數(shù)怎么使用?
2 回答直接用$("li").css("color","red")與整個(gè)each的方法效果是一樣的。有什么區(qū)別或好處么
2 回答用each()方法點(diǎn)擊列表彈出此列表的內(nèi)容
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-12-14
2016-12-14
?i = 0;
? ? $("button:last").click(function() {
? ? ? ? $("li").each(function(index, element) { ? ? ? ?
? ? ? ? ? ? if (index == i) {
? ? ? ? ? ? ? ? $(this).css('color','blue');
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? i++;
? ? })
2016-10-30
思路就是加個(gè)定時(shí)器,延時(shí)變色。比如第1個(gè)li過(guò)200毫秒變成紅色,第2個(gè)li過(guò)400毫秒再變成紅色...