我正在尝试使用香草javascript创建待办事项列表,当将文本输入到文本输入中时,它将动态创建
我尝试将display: table-cell;
vertical-align center
添加到
display: flex
和单选按钮上的justify-content: flex-end;
,但是这会将单选按钮移到另一个位置,但仍然不正确。
我把代码放在了一个小提琴中:https://jsfiddle.net/oub5pm4g/
document.querySelector("#add").addEventListener("click", btnClick);
document.querySelector("#input").addEventListener("keyup", keyUp)
function keyUp(event) {
if (event.keyCode === 13) {
event.preventDefault();
btnClick();
}
}
function btnClick(event) {
event.preventDefault()
var input = document.querySelector("#input");
var ul = document.querySelector("ul");
li = document.createElement("li");
ul.appendChild(li);
h2 = document.createElement("h2");
text = document.createTextNode(input.value);
h2.appendChild(text);
li.appendChild(h2);
var radio = document.createElement("input");
radio.setAttribute("type", "radio");
li.appendChild(radio);
document.querySelector("#form").reset();
}
body {
background: rgb(238, 237, 237);
}
.container {
background: white;
max-width: 50%;
max-height: 80%;
margin: 0 auto;
border-radius: 25px;
padding: 2%;
box-shadow: 0 5px 10px rgba(154, 160, 185, 0.05),
0 15px 40px rgba(166, 173, 201, 0.2);
}
h1 {
font-family: "Roboto", sans-serif;
font-weight: 900;
text-align: center;
}
h2 {
font-weight: 600;
}
h3 {
font-weight: 00;
}
h4 {
font-weight: 100;
}
ul {
list-style: none;
padding: 0;
font-family: "Roboto", sans-serif;
margin-top: 5%;
color: white;
}
li {
box-sizing: border-box;
width: 100%;
margin-bottom: 5%;
font-size: 1em;
background: crimson;
padding: 1em;
border-radius: 15px;
}
input[type="text"] {
box-sizing: border-box;
width: 85%;
font-size: 1em;
padding: 1em;
}
input[type="radio"] {
float: right;
align-content: center;
}
button {
padding: 1em;
width: 13%;
font-size: 1em;
color: white;
background: crimson;
margin-left: 1.4%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>To-Do List</h1>
<form id="form">
<input type="text" placeholder="Add new task..." id="input">
<button id="add" type="submit">Add</button>
</form>
<ul>
</ul>
</div>
</body>
<script src="main.js"></script>
</html>
谢谢。
答案 0 :(得分:2)
尝试使用Three successive measures:
using the Rating Data from the table above
Equipment_Number Max
A1A 2
A1B 1
A2A 4
A2B 4
B1A 1
B1B 4
B2A 2
B2B 3
using the Equipment_Number max measure grouping by uniqueID
uniqueID Max
A1 2
A2 4
B1 4
B2 3
using the uniqueID max measure grouping by Name
Name Average
A 3
B 3.5
标签上的flex
属性
li
li {
display: flex;
justify-content: space-between;
align-items: center;
}
document.querySelector("#add").addEventListener("click", btnClick);
document.querySelector("#input").addEventListener("keyup", keyUp)
function keyUp(event) {
if (event.keyCode === 13) {
event.preventDefault();
btnClick();
}
}
function btnClick(event) {
event.preventDefault()
var input = document.querySelector("#input");
var ul = document.querySelector("ul");
li = document.createElement("li");
ul.appendChild(li);
h2 = document.createElement("h2");
text = document.createTextNode(input.value);
h2.appendChild(text);
li.appendChild(h2);
var radio = document.createElement("input");
radio.setAttribute("type", "radio");
li.appendChild(radio);
document.querySelector("#form").reset();
}
body {
background: rgb(238, 237, 237);
}
.container {
background: white;
max-width: 50%;
max-height: 80%;
margin: 0 auto;
border-radius: 25px;
padding: 2%;
box-shadow: 0 5px 10px rgba(154, 160, 185, 0.05), 0 15px 40px rgba(166, 173, 201, 0.2);
}
h1 {
font-family: "Roboto", sans-serif;
font-weight: 900;
text-align: center;
}
h2 {
font-weight: 600;
}
h3 {
font-weight: 00;
}
h4 {
font-weight: 100;
}
ul {
list-style: none;
padding: 0;
font-family: "Roboto", sans-serif;
margin-top: 5%;
color: white;
}
li {
box-sizing: border-box;
width: 100%;
margin-bottom: 5%;
font-size: 1em;
background: crimson;
padding: 1em;
border-radius: 15px;
display: flex;
justify-content: space-between;
align-items: center;
}
input[type="text"] {
box-sizing: border-box;
width: 85%;
font-size: 1em;
padding: 1em;
}
input[type="radio"] {
float: right;
align-content: center;
}
button {
padding: 1em;
width: 13%;
font-size: 1em;
color: white;
background: crimson;
margin-left: 1.4%;
}