首页 > 代码库 > 自定义属性应用

自定义属性应用

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            li {
                list-style: none;
                width: 114px;
                height: 140px;
                background: url(img/normal.png);
                float: left;
                margin-right: 20px;
            }
        </style>
        <script>
            window.onload = function() {
                var oLi = document.getElementsByTagName(li);
                for(var i = 0; i < oLi.length; i++) {
                    oLi[i].onOff = true;
                    oLi[i].onclick = function() {
                        if(this.onOff) {
                            this.style.background = url(img/active.png);
                            this.onOff = false;
                        } else {
                            this.style.background = url(img/normal.png);
                            this.onOff = true;
                        }
                    }
                }
            }
        </script>
    </head>

    <body>
        <ul>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </body>

</html>

 

自定义属性应用