<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document
</title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
var ol = document.createElement("ol");
for(let i = 0; i < 10;i++){
var li = document.createElement("li");
var a = document.createElement("a");
a.setAttribute("href", "javascript:void(0)");
a.innerText = "demo"+i;
if (i % 2==0) {
li.style.background = 'orange';
}else {
li.style.background = 'red';
}
li.appendChild(a);
ol.appendChild(li);
}
document.body.appendChild(ol);
var ul = document.createElement("ul");
ul.style.marginTop = "20px";
for(let i = 0; i < 10;i++){
var li = document.createElement("li");
var a = document.createElement("a");
a.setAttribute("href", "javascript:void(0)");
a.innerText = "demo"+i;
if (i % 2==0) {
li.style.background = 'blue';
}else {
li.style.background = 'red';
}
li.appendChild(a);
ul.appendChild(li);
}
document.body.appendChild(ul);
var dl = document.createElement("dl");
dl.style.marginTop = "20px";
var dt = document.createElement("dt");
dt.innerText = "自定义";
dt.style.textAlign = "center";
dl.appendChild(dt);
for(let i = 0; i < 10;i++){
var dd = document.createElement("dd");
var a = document.createElement("a");
a.setAttribute("href", "javascript:void(0)");
a.innerText = "demo"+i;
if (i % 2==0) {
dd.style.background = 'black';
}else {
dd.style.background = 'white';
}
dd.appendChild(a);
dl.appendChild(dd);
}
document.body.appendChild(dl);
</script>
转载请注明原文地址: https://www.6miu.com/read-17871.html