</pre><pre name="code" class="html"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>隔行變色</title>
<script type="text/javascript">
window.onload = function() {
var oUl = document.getElementById("u1");
//ul
var aLi = oUl.getElementsByTagName("li");
//下面的li數組
var i = 0;
for ( i = 0; i < aLi.length; i++) {
if (i % 2 == 0) {
aLi[i].style.background = '#ff0000';
}
}
};
</script>
</head>
<body>
<ul id="u1">
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
</body>
</html>
javascript_隔行變色
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.