我在网上看到有人这样写:
getElementById("").style.display="none"
还有一个是getElementById("").attributes['class'].value = ''我查了下知道是通过Id得到display的属性和class的属性,我想问下,要得到display必须用.style吗?attributes是得到class,那我可以写成attributes['display']吗?attributes和style有什么区别?

解决方案 »

  1.   

    给你看个示例,希望你能看明白
    <div id="test" class="testCss" style="display:none;font-size:12px"></div>
    是否看明白了?
      

  2.   

    要得到display必须用.style吗?

    attributes是得到class,那我可以写成attributes['display']吗?
    不可以
    attributes和style有什么区别?
    <td id="tdId" class="c1" style="display:none"></td>
    id,class,style都是属性
    attributes是属性集合
    通过getElementById("").attributes['style']能得到style属性
      

  3.   

    attributes是一个集合,得通过下标来访问(准确的说,是个map,通过key来访问)。
    getElementById("").style
    getElementById("").attributes['style']
    我觉得这两种写法是一样的。另外,目前流行的js框架,已经不需要写如此冗长的代码了,很方便。你可以试试。