情况如下
<button class="stately" id="stately" value="1" onclick="updateFlag(this);">牢固</button>class="stately" 是我调用的一个style样式(html) ,这个样式里面有个属性color.我现在遇到的问题就是 我希望在updateFlag(this) 这个js函数里面如何获取到这个样式的颜色的值?谢谢!!

解决方案 »

  1.   

    function updateFlag(obj){
    var color = obj.style.color;
    alert(color);
    }
      

  2.   

    你把你那个样式定义发上来撒this.style.color 怎么取不到? 不可能,除非是没有
      

  3.   


    用JQUERY 
    先下JQUERY.JS
    var str_color = $('stately').attr('color');
    alert(str_color);
      

  4.   

    用JQUERY 
    先下JQUERY.JS
    var str_color = $('#stately').attr('color');
    alert(str_color);
      

  5.   

    <!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=gbk"/>
    </head><style type="text/css">
    .background { background-color:Gray; width:150px; }
    .word { color:red; font-size:12px; height:100px; }
    </style><script type="text/javascript">if (!window.getComputedStyle) {
      window.getComputedStyle = function(element) {
        if (!element) throw 'element is null or undefined';
        if (!element.currentStyle) throw 'element unsupport currentStyle';
        var cs = element.currentStyle;
        !cs.getPropertyValue && (cs.getPropertyValue = function(css) {
            return this[css];
          });
        return cs;
      };
    }window.onload = function() {
      var content = document.getElementById('content');
      var color = window.getComputedStyle(content).getPropertyValue('background-color');
      alert(color);
    }</script><body>
    <div id="content" class="background word">test</div>
    </body>
    </html>