【问题标题】:Why isn't obj.style.left = "200px"; working in this code?为什么不是 obj.style.left = "200px";在这段代码中工作?
【发布时间】:2010-11-18 16:05:34
【问题描述】:

为什么.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>

【问题讨论】:

  • 每个元素的position 设置是什么?

标签: javascript css javascript-events


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 2022-06-17
    • 2014-03-16
    • 2010-09-18
    相关资源
    最近更新 更多