<div class="codetitle"> <span><a style="CURSOR: pointer" data="70127" class="copybut" id="copybut70127" onclick="doCopy('code70127')"><u>複製程式碼</u></a></span>程式碼如下:</div> <div class="codebody" id="code70127"> <br><br><br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br>js取模隔行變色<br><script type="text/javascript"><BR>window.onload=function()<BR>{<BR> var oUl=document.getElementById ('ul1');<BR> var aLi=oUl.getElementsByTagName('li');<br><br> for(var i=0; i< aLi .length; i )<BR> {<BR> if (i%2==0) / /取模求餘數<BR> {<BR> aLi[i].style.background='red';<BR> }<BR> }<BR>}<BR>< ;/script><BR></ script><BR><body><BR><ul id="ul1"><BR> <li>webtall<BR> <li>webtall<BR> <li >webtall<BR> <li>webtall<BR> <li>webtall<BR> <BR><BR></script> </div>