为什么不是obj.style.left ="200px"; 在这段代码中工作?

Bab*_*ker 2 javascript css javascript-events

为什么不能.style.top = "200px";在这段代码中工作?在元素中调用事件oclick="this.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>
Run Code Online (Sandbox Code Playgroud)

Jos*_*ell 7

要使用lefttop样式元素必须是position:absolute,或position:relative,或position:fixed