Home  >  Q&A  >  body text

关于js中修改css样式的问题?

获取标签对象 obj

obj.style="background-color:red"

obj.style="backgroundColor:red"

这两种 那种 对   为啥都没反应???


checkcheck2859 days ago1390

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:38:04

    About the problem of modifying css style in js? -PHP Chinese website Q&A-About the problem of modifying css style in js? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • 迷茫

    迷茫2016-12-22 16:57:02

    obj.style="background-color:red"

    obj.style="backgroundColor:red"

    上述写法是混淆了CSS和DOM(具体说来就是javascript)这两个内容的语法规则。在CSS中,设置背景颜色可以在标签中的属性设为“background-color:red”。而在DOM中,设置背景颜色,需要用到属性sty.backgroundColor,将其设置为red,而且写法为:“obj.style.backgroundColor="red";”


    reply
    1
  • Cancelreply