代码之家  ›  专栏  ›  技术社区  ›  ZA.

为什么以下Javascript代码(用于设置CSS样式)不起作用?

  •  1
  • ZA.  · 技术社区  · 17 年前

    document.getElementById(obj).style='font-weight:bold; color:#333;';
    

    但它不起作用。有人知道为什么吗?

    3 回复  |  直到 17 年前
        1
  •  8
  •   guerda    17 年前

    document.getElementById(obj).style.fontWeight='bold';
    document.getElementById(obj).style.color='#333';
    
        2
  •  6
  •   ZA.    16 年前

    cssText

    document.getElementById('xx').style.cssText='font-weight:bold; color:#333;';
    
        3
  •  0
  •   Liu Peng    17 年前