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>
要使用left
或top
样式,元素必须是position:absolute
或position:relative
或position: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.