code如下:
<html>
<head>
<style type="text/css">
input { position:relative;}
</style>
<script type="text/javascript">
function f() {
var em = document.getElementById("mine");
var em1 = document.createElement("input");
em1.setAttribute("value", "1");
em1.setAttribute("type", "button");
var em2 = document.createElement("input");
em2.setAttribute("value", "2");
em2.setAttribute("type", "button");
var em3 = document.createElement("input");
em3.setAttribute("value", "3");
em3.setAttribute("type", "button");
var em4 = document.createElement("input");
em4.setAttribute("value", "4");
em4.setAttribute("type", "button");
em1.style.left = "100px";
em1.style.top = "100px";
em2.style.left = "150px";
em2.style.top = "100px";
em3.style.left = "100px";
em3.style.top = "150px";
em4.style.left = "150px";
em4.style.top = "150px";
em.appendChild(em1);
em.appendChild(em2);
em.appendChild(em3);
em.appendChild(em4);
}
window.onload = f;
</script>
</head>
<body>
<div id="mine"></div>
</body>
</html>
在我想象中,四个button在网页中应该呈现田字形,
1 2
3 4
可是实际上看到的是交错开的四个button
1 2
3 4
我想不明白,这是怎么回事呢?应该如何在javascript里面设置位置呢?谢谢。
--
FROM 99.234.97.*