day21
点击按钮,插入表格
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
button {
width: 100px;
height: 50px;
}
tr {
border: 1px solid red;
}
td {
border: 1px solid red;
}
</style>
</head>
<body>
<input type="text">
<input type="text">
<input type="text">
<button id="btn"></button>
<table></table>
</body>
<script>
var oinput = document.querySelectorAll("input")
var obtn = document.querySelector("button")
var obady = document.querySelectorAll("body")
obtn.onclick = function () {
var table = document.createElement("table")
document.body.appendChild(table)
var tr = document.createElement("tr")
table.appendChild(tr)
// var tdf = document.createElement("td")
// tdf.innerHTML = oinput[0].value
// var tds = document.createElement("td")
// tds.innerHTML = oinput[1].value
// var tdt=document.createElement("td")
// tdt.innerHTML=oinput[2].value
for (var i = 0; i < oinput.length; i++) {
var oTd = document.createElement("td")
oTd.innerHTML = oinput[i].value
tr.appendChild(oTd)
}
var tdfo = document.createElement("td")
tdfo.innerHTML = "<button οnclick='btn1(this)'>删除</button>"
// tr.appendChild(tdf)
// tr.appendChild(tds)
// tr.appendChild(tdt)
tr.appendChild(tdfo)
}
function btn1(o) {
o.parentNode.parentNode.remove()
}
</script>
</html>