cesium 同时创建多个div 并且放置在不同的位置
时间: 2024-05-14 12:18:28 浏览: 11
你可以使用 JavaScript 中的 DOM 操作来创建和放置多个 DIV 元素。以下是一个简单的示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>Multiple DIVs</title>
</head>
<body>
<script>
// 创建多个 DIV 元素
for (let i = 0; i < 5; i++) {
const div = document.createElement("div");
div.textContent = `DIV ${i+1}`;
document.body.appendChild(div);
}
// 放置 DIV 元素在不同的位置
const div1 = document.getElementsByTagName("div")[0];
div1.style.position = "absolute";
div1.style.top = "50px";
div1.style.left = "50px";
const div2 = document.getElementsByTagName("div")[1];
div2.style.position = "absolute";
div2.style.top = "100px";
div2.style.left = "100px";
const div3 = document.getElementsByTagName("div")[2];
div3.style.position = "absolute";
div3.style.top = "150px";
div3.style.left = "150px";
const div4 = document.getElementsByTagName("div")[3];
div4.style.position = "absolute";
div4.style.top = "200px";
div4.style.left = "200px";
const div5 = document.getElementsByTagName("div")[4];
div5.style.position = "absolute";
div5.style.top = "250px";
div5.style.left = "250px";
</script>
</body>
</html>
```
这个示例将创建五个 DIV 元素,然后将它们放置在不同的位置。你可以使用 `document.createElement()` 创建一个新的元素,使用 `appendChild()` 将它添加到 body 元素中。然后使用 `style` 属性设置元素的位置和样式。