通过js实现隔行变色效果

通过js实现隔行变色效果

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>
        <li>ul_li_1</li>
        <li>ul_li_2</li>
        <li>ul_li_3</li>
        <li>ul_li_4</li>
        <li>ul_li_5</li>
        <li>ul_li_6</li>
        <li>ul_li_7</li>
        <li>ul_li_8</li>
        <li>ul_li_9</li>
        <li>ul_li_10</li>
    </ul>
    <script>
        var lis = document.querySelectorAll("li");
        for (var i = 0; i < lis.length; i++) {
            if (i % 2 == 0) {
                lis[i].style.backgroundColor = "#0f0";
            } else {
                lis[i].style.backgroundColor = "#00f";
            }
        }
    </script>
</body>

</html>

通过js实现隔行变色效果

上一篇:jQuery:遍历节点


下一篇:2021-06-14