gutenye / learn-feng

hello
0 stars 0 forks source link

thorny #11

Open 642495539 opened 8 years ago

642495539 commented 8 years ago
//html

<div id=id3>
<div id=id4></div>
<div id=id5></div>
</div>

//style.css
#id3{
width:800px;
height:200px;
    position:relative;
    background-color:#699;

}
#id4{
    width:50px;
    height:50px;
    background-color:red;
position:absolute;
left:0px;
top:0px;
}
#id5{
    width:50px;
    height:50px;
    background-color:green;
    position:absolute;
    left:0px;
    top:150px;

}

//js
alert(document.getElementById("id4").style.left);           //null
document.getElementById("id4").style.left="0px";
alert(document.getElementById("id4").style.left);          //0px

//
在外部css文件中已经定义了left的值了,为什么输出null?(从网页输出布局来看position  left  top等值都已经起到作用了)
gutenye commented 8 years ago

css文件里面的东西 不能用document.getElementById("id4").style.left这种方式来访问的. 但有个方法可以访问, 比较复杂我就不介绍了