开发者

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>开发者_JS百科
    <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>


To use a left or top style the element must be position:absolute, or position:relative, or position:fixed

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜