简体   繁体   中英

Why isn't obj.style.left = "200px"; working in this code?

Why wont .style.top = "200px"; work in this code? Calling the event within the element using oclick="this.style.left='200px';"doesn't work either.

<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>

要使用lefttop样式,元素必须是position:absoluteposition:relativeposition:fixed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM