60 lines
1.7 KiB
HTML
60 lines
1.7 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="zh">
|
||
|
<head>
|
||
|
<meta charset="UTF-8" />
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
|
<title>颜色记录器</title>
|
||
|
<style>
|
||
|
#colors {
|
||
|
display: flex;
|
||
|
flex: wrap;
|
||
|
margin-top: 20px;
|
||
|
}
|
||
|
#colors div {
|
||
|
background-color: white;
|
||
|
border: 1px black solid;
|
||
|
border-radius: 5px;
|
||
|
width: 100px;
|
||
|
height: 100px;
|
||
|
text-align: center;
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
justify-content: center;
|
||
|
margin: 10px;
|
||
|
color: white;
|
||
|
font-weight: 900;
|
||
|
font-family: monospace;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<h1>颜色记录器</h1>
|
||
|
<input type="text" id="colorname" placeholder="颜色名" />
|
||
|
<input type="text" id="colorvalue" placeholder="颜色值" />
|
||
|
<button onclick="append()">添加</button>
|
||
|
<div id="colors">
|
||
|
<div style="background-color: red">红<br />red</div>
|
||
|
<div style="background-color: green">绿<br />green</div>
|
||
|
<div style="background-color: blue">蓝<br />blue</div>
|
||
|
</div>
|
||
|
<script>
|
||
|
function append() {
|
||
|
//创建一个div元素。
|
||
|
const newcolor = document.createElement("div");
|
||
|
newcolor.innerHTML = `${colorname.value}<br>${colorvalue.value}`;
|
||
|
newcolor.setAttribute(
|
||
|
"style",
|
||
|
`background-color: ${colorvalue.value};`
|
||
|
);
|
||
|
colors.appendChild(newcolor);
|
||
|
function lion() {
|
||
|
const lion = bocument.createElement("img");
|
||
|
lion.setAttribute("src", "../image/ryan.png");
|
||
|
lion.setAttribute();
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|