请问如何获取一个超链接的背景颜色?或者是如果判断 超链接背景色和超链接本身的颜色是否一样? 比如背景色是白色,超链接也是白色,那么如何用js去检测它们?请高人指教
?

解决方案 »

  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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    a{
    background-color:#00FF00;
    color:#0000FF;
    }
    </style>
    <script type="text/javascript">
    function getStyle(obj){
    var style="";
    if(document.defaultView&&document.defaultView.getComputedStyle){
    style=document.defaultView.getComputedStyle(obj);;
    }else{
    style=obj.currentStyle;
    }
    return style;
    }
    function init(){
    var as=document.getElementsByTagName("a")[0];
    as.onclick=function(e){
    var style=getStyle(this);
    alert(style.backgroundColor+":"+style.color);
    var a=e||window.event;
    if(a.preventDefault){
    a.preventDefault();
    }else{
    a.returnValue=false;
    }
    }
    }
    window.onload=init;
    </script>
    </head><body>
    <a href="">ss</a>
    </body>
    </html>
    大体这样试试