我现在有一个页面a其中有4个超连接,目标地址都是a,现在希望点过以后的连接显示跟其他的连接不同,当再点另一个连接后其他的样子一致,刚点过的特殊,也就是说有1,2,3,4这四个连接,点1,连接到a,此时1的显示情况跟2,3,4不同,而点2,后1,3,4显示的相同.

解决方案 »

  1.   

    <script>
    var currentA = null;
        window.onload = function(){
            var a = document.getElementsByTagName('a');
            for ( var i = 0; i < a.length; i++ ) {
                a[i].onclick = function() {
                 if (currentA != null)
                 {
                 currentA.parentNode.style.backgroundColor = 'white';
                 }
                 currentA = this;
                    this.parentNode.style.backgroundColor = 'blue';
                };
            }
        };
        </script>
    </head>
    <body>
      <div><a href="#">xxxx</a></div>
      <div><a href="#">xxxx</a></div>
      <div><a href="#">xxxx</a></div>
      <div><a href="#">xxxx</a></div>
    </body>
    </html>