目前,我正在创建一个接受名字和姓氏的表.在填写完一行之后,我想要出现一个新行(现在,我只是在制作一个按钮,这样我就可以正确地使用这个功能).
在这一行中,我想创建两个单元格,其中有文本输入,可用于其他名称.
Question:如何将文本输入插入到我的HTML表格行和单元格中?
const table = document.querySelector('#table');
function lineMessage(msg) {
document.querySelector('#myMessage').textContent += msg;
}
function groupMessage(msg) {
document.querySelector('#myMessage').innerHTML += msg + '<br/>';
}
function addRow() {
var row = table.insertRow(2);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "cell1";
cell2.innerHTML = "cell2";
}
th {
width: 50vmin;
height: 10vmin;
font-size: 20pt;
}
td {
width: 50vmin;
height: 5vmin;
}
input {
width: 100%;
height: 100%;
text-align: center;
align-items: center;
font-size: 18pt;
font-weight: 500;
font-family: Georgia, 'Times New Roman', Times, serif;
width: 100%;
border: 0;
}
#submit {
background-color: blue;
color: white;
border: 0;
position: relative;
left: 82vmin;
}
#myConsole {
background-color: black;
color: white;
height: 25vmin;
}
<!DOCTYPE html>
<html lang="en">
<html>
<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">
<meta name="author" content="Christian Davis">
<link rel="stylesheet" href="styles.css">
<title>Random Group Generator</title>
</head>
<body>
<table id="table" border="1">
<tr>
<th>First Name:</th>
<th>Last Name:</th>
</tr>
<tr>
<th><input type="text"></th>
<th><input type="text"></th>
</tr>
</table> <br>
<button onclick="addRow()">Add Row</button>
<button id="submit">Submit</button>
<p id="myConsole">> <span id="myMessage"></span></p>
<script src="app.js"></script>
</body>
</html>