本文主要是介绍JS 隔行变色,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<script type="text/javascript">window.οnlοad=function(){
var oUl=document.getElementById('ul1');
var aLi=oUl.getElementsByTagName('li');
for(var i=0; i< aLi .length; i++) {
if(i%2==0) //取模 求余数
{
aLi[i].style.background='red';
}
}
}
</script>
<ul id="ul1">
<li>webtall</li>
<li>webtall</li>
<li>webtall</li>
<li>webtall</li>
<li>webtall</li>
</ul>
<head runat="server">
<title></title>
<script type="text/javascript">
window.onload = function () {
var otab = document.getElementById('tab1');
var thiscolor = '';
for (var i = 0; i < otab.tBodies[0].rows.length; i++) {
otab.tBodies[0].rows[i].onmouseover = function () {
thiscolor = this.style.background;
this.style.background = '#00FFFF';
};
otab.tBodies[0].rows[i].onmouseout = function () {
this.style.background = thiscolor;
};
if (i % 2) {
otab.tBodies[0].rows[i].style.background = '';
}
else {
otab.tBodies[0].rows[i].style.background = '#FFFF00';
}
}
};
</script>
这篇关于JS 隔行变色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!