function changeBgColor(element) {

alert(element.style.backgroundColor.value);
if(element.style.backgroundColor == "#123456") {
element.style.backgroundColor = "#111111";
} else {
element.style.backgroundColor = "#222222";
}
}aler()出的值为undefined 请问大虾 我改如何用JavaScript判断这个element在css中的backgroundColor值呢?
谢谢~~

解决方案 »

  1.   

    不知道 .value是不是属性,去查一下吧
      

  2.   


    alert(element.style.backgroundColor);这样可以吗,不加value,我这边可以!
      

  3.   

    我不会写jQuery 麻烦大虾帮写下~~
      

  4.   

    function changeBgColor(element) {alert(element.style.backgroundColor);
    if(element.style.backgroundColor == "#123456") {
    element.style.backgroundColor = "#111111";
    } else {
    element.style.backgroundColor = "#222222";
    }
    }
      

  5.   

    你的元素本身有没有style这个属性,在这个属性中有没有backgroundColor:这个值的设置
      

  6.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <script   type= "text/javascript"   src= "jquery-1.2.6.js"> </script> 
      <script   type= "text/javascript">
    $(function(){
    $("#ch").click(function(){
    alert($(this).css("background-color"));
    if($(this).css("background-color")=="#123456"){
    $(this).css("background-color","#111111")
    }else{
    $(this).css("background-color","#222222")
    }
    });
    }) function changeBgColor(element) {
    alert(element.style.backgroundColor);
    if(element.style.backgroundColor == "#123456") {
    element.style.backgroundColor = "#111111";
    } else {
    element.style.backgroundColor = "#222222";
    }
    }  </script>
     </HEAD> <BODY>
      <input id="ch" type="button" style="background-color:#123456;" value="changeColorJquery"/>
      <input id="ch" type="button" style="background-color:#120000;" value="changeColorJS" onclick="changeBgColor(this)"/>
     </BODY>
    </HTML>
      

  7.   

    听说可以用hex 转换grb和16进制的格式 麻烦帮我写一个吧~~
      

  8.   

    http://www.javascripter.net/faq/hextorgb.htm
    http://www.javascripter.net/faq/rgbtohex.htm
      

  9.   

    alert(element.style.backgroundColor);
    去掉。value
      

  10.   

    $("#elemtntID").css("background");