admin管理员组文章数量:1312662
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>
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>
Share
Improve this question
edited Jun 16, 2022 at 12:27
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Nov 18, 2010 at 16:05
BabikerBabiker
18.8k28 gold badges82 silver badges127 bronze badges
1
-
1
What are the
position
's set to for each element? – Evan Mulawski Commented Nov 18, 2010 at 16:07
1 Answer
Reset to default 9To use a left
or top
style the element must be position:absolute
, or position:relative
, or position:fixed
本文标签: javascriptWhy isn39t objstyleleftquot200pxquot working in this codeStack Overflow
版权声明:本文标题:javascript - Why isn't obj.style.left = "200px"; working in this code? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741896397a2403599.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论