点新闻时,新闻变红,其它黑 
点健康时,健康变红,其它黑 ---可以修改想变的颜色
<html> 
<style> 
a{color:black;} 
</style> 
<script language= "JavaScript "> 
var currenta = null; 
function clicka(a) 

if (currenta != null) 

currenta.style.color = "black "; 

currenta = a; 
a.style.color = "red "; 

</script> 
<body> 
| <a href= "# " onclick= "clicka(this) "> 新闻 </a> | <a href= "# " onclick= "clicka(this) "> 健康 </a> | <a href= "# " onclick= "clicka(this) "> 人才 </a> | <a href= "# " onclick= "clicka(this) "> 管理 </a> | 
</body> 
</html>

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <style type="text/css">
            .bianse
            {
                color: Purple;
            }
            .bianse1
            {
              color:Blue;  
            }
            
        </style>
        <script type="text/javascript">
            function showsubmenu(sid) {
                if (document.getElementById(sid).className == "bianse") {
                    for (i = 1; i < 4; i++) {
                        if (i != sid) {
                            document.getElementById(i).className = "bianse1";
                        }
                    }
                }
                else
                {
                    document.getElementById(sid).className = "bianse"
                    for (i = 1; i < 4; i++) {
                        if (i != sid) {
                            document.getElementById(i).className = "bianse1";
                        }
                    }
                }
            };
        </script>
    </head>
    <body>
        <ul>
            <li><a id="1" class="bianse" href="#" onclick="showsubmenu(this.id)">导航1</a> </li>
            <li><a id="2" href="#" onclick="showsubmenu(this.id)">导航2</a> </li>
            <li><a id="3" href="#" onclick="showsubmenu(this.id)">导航3</a> </li>
        </ul>
    </body>
    </html>代码献上~
      

  2.   

    因为网页a标签点击默认就变颜色,你可以设置两个class进行切换~
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <style type="text/css">
            .bianse
            {
                color: Purple;
            }
            .bianse1
            {
                color: Blue;
            }
        </style>
        <script type="text/javascript">
            function showsubmenu(sid) {            for (i = 1; i < 4; i++) {
                    if (i == sid) {
                        if (document.getElementById(sid).className != "bianse") {
                            document.getElementById(sid).className = "bianse"
                        }
                    }
                    else {
                        document.getElementById(i).className = "bianse1";
                    }
                }
            };
        </script>
    </head>
    <body>
        <ul>
            <li><a id="1" class="bianse" href="#" onclick="showsubmenu(this.id)">导航1</a> </li>
            <li><a id="2" class="bianse1" href="#" onclick="showsubmenu(this.id)">导航2</a> </li>
            <li><a id="3" class="bianse1" href="#" onclick="showsubmenu(this.id)">导航3</a> </li>
        </ul>
    </body>
    </html>
    简化了下,瞬间亮了有木有~