我对javascirpt不是很懂,楼上说的没明白,
我是想这么做,给每个连接加一个onclick事件
在事件中首先将页面所有连接还原为默认色,然后把当前
选种的设为不同色,不知道能不能实现,如果能怎么实现

解决方案 »

  1.   

    function changestyle()
      {
        
        for(i=0;i<document.links.length;i++)
        {
           document.links(i).style.color = 'blue';
        }
        this.style.color= 'red';
        
        
         window.alert('hello');
      }
      function setstyle()
      {
      for(i=0;i<document.links.length;i++)
        {
           document.links(i).style.color = 'blue';
        }
         
      }
    怎么使当前选中的样式改变,我用this不行
      

  2.   

    <a href=#>1111</a><br>
    <a href=#>2222</a><br>
    <a href=#>3333</a><br>
    <a href=#>44444</a><SCRIPT LANGUAGE="JavaScript">
    <!--
    var _mm = null;
    document.onclick = function()
    {
      var e = window.event.srcElement;
      if(e.tagName == "A")
      {
        e.style.backgroundColor = "yellow";
        if(_mm) _mm.style.backgroundColor = "";
        _mm = e;
      }
    }
    //-->
    </SCRIPT>
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="Seagle.K">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <base target="_blank">
    <script language="JavaScript">
    var lastlink;function bindclick()
    {
    var o = document.getElementsByTagName('a');
    for (var i=0; i<o.length; i++)
    {
    o[i].attachEvent("onclick", new Function("aclick()"));
    }
    }function aclick()
    {
    var srcElement = event.srcElement;
    srcElement.className="special";
    if (typeof(lastlink) != 'undefined')
    {
    lastlink.className="";
    }
    lastlink=srcElement;
    }
    </script>
    <style type="text/css">
    a.special:link { text-decoration: none; color: red; } 
    a.special:active { text-decoration: none; color: red; } 
    a.special:visited { text-decoration: none; color: red; } 
    a.special:hover { text-decoration: none; color: red; } a:link { text-decoration: underline; color: black; }
    a:active { text-decoration: underline; color: black; }
    a:visited { text-decoration: underline; color: black; }
    a:hover { text-decoration: underline; color: black; }
    </style>
    </head>
    <body onload="bindclick()">
    <a href="http://www.blogcn.com/user2/eosin/index.html">go</a><br>
    <a href="http://www.blogcn.com/user2/eosin/index.html">goo</a><br>
    <a href="http://www.blogcn.com/user2/eosin/index.html">gooo</a></br>
    <a href="http://www.blogcn.com/user2/eosin/index.html">goooo</a></br>
    <a href="http://www.blogcn.com/user2/eosin/index.html">gooooo</a></br>
    </body>
    </html>