2010-11-18 3 views
2

なぜこのコードで.style.top = "200px";が効かないのですか? oclick="this.style.left='200px';"を使用して要素内でイベントを呼び出すこともできません。なぜobj.style.left = "200px"でないのですか?このコードで作業していますか?

<html> 
    <head> 
    </head> 
    <body> 
     <div id="theDiv">The Div</div> 
     <button id="theButton">Do</button> 
    </body> 
</body> 
</html> 
<script type="text/javascript"> 
    document.getElementById("theButton").onclick = function(){ 
     document.getElementById("theDiv").style.top = "200px"; 
    }; 
</script> 
+1

各要素のためにに設定され 'position'年代どのようなものでなければなりませんleftまたはtopスタイルを使用するには? –

答えて

7

要素がposition:absolute、またはposition:relative、またはposition:fixed

+1

...または 'position:fixed;' –

+0

@Matt Ball - ありがとうございます。 –