var a = document.getElementsByTagName("li"); for(var i = 0,j = 1,len=a.length;i<len;i++;){ if((i + 1) % 2 ! = 0){ a[i].innerHTML = "第" + j + "名:"+a[i].innerHTML; a[i].className = "red"; j++; } else { a[i].innerHTML = "第"+j+"名:"+a[i].innerHTML; j++ } }
1 回答
兼容并包
TA贡献83条经验 获得超67个赞
var a = document.getElementsByTagName("li"); for(var i = 0,j = 1;i<a.length;i++){ if((i + 1)%2!= 0){ a[i].innerHTML = "第" + j + "名:"+a[i].innerHTML; a[i].className = "red"; j++; } else { a[i].innerHTML = "第"+j+"名:"+a[i].innerHTML; j++ } } 这就可以了,希望对你有帮助
添加回答
举报
0/150
提交
取消