我在网上看到有人这样写:
getElementById("").style.display="none"
还有一个是getElementById("").attributes['class'].value = ''我查了下知道是通过Id得到display的属性和class的属性,我想问下,要得到display必须用.style吗?attributes是得到class,那我可以写成attributes['display']吗?attributes和style有什么区别?
.style.display = "none" [color=red]专门控制style[/color] 对应的是
.style.borderColor = "red" 对应的是
也可以通过下面方法:
1. document.getElementById('page').setAttribute("style","display:none;")
2. document.getElementById('page').setAttribute("style","border-color:red;")
但是它会覆盖整个style
2 执行后 1 的 display:none; 就会没掉
会变成:
而 .style.borderColor = "red" 不会覆盖整个style,它不影响别的style
class 对应的是
它也可以用 document.getElementById('page').setAttribute("class", "display-none") 来设置
它要先定义 style
display是作用于style的,attribute中的更改不会有作用