<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
li {
background-color: blue;
}
</style>
<script>
window.onload = function() {
/* var second = 183;
console.log(183 % 60); */
var aLi = document.getElementsByTagName('li');
console.log(aLi);
for (var i = 0; i < aLi.length; i++) {
/* alert(1); */
if (i % 2 == 1) {
console.log(i);
aLi[i].style.background = 'red';
}
}
};
</script>
</head>
<body>
<ul id="ul1">
<li>1111</li>
<li>2222</li>
<li>3333</li>
<li>4444</li>
</ul>
<!-- 運算符 -->
</body>
</html>
運行結果