为什么不是obj.style.left =" 200px" ;;在这段代码中工作? [英] Why isn't obj.style.left = "200px"; working in this code?
本文介绍了为什么不是obj.style.left =" 200px" ;;在这段代码中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么不会 .style.top =200px;
在此代码中工作?使用 oclick =this.style.left ='200px';
在元素内调用事件也不起作用。
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>
推荐答案
使用左
或 top
样式元素必须 position:absolute
或 position:relative
,或 position:fixed
To use a left
or top
style the element must be position:absolute
, or position:relative
, or position:fixed
这篇关于为什么不是obj.style.left =" 200px" ;;在这段代码中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文