我创建了下一个代码:
var b = document.getElementById("btn");
b.addEventListener('click', function () {
var a = document.createElement("input");
document.getElementById('container').appendChild(a);
});
var c = document.getElementById('btn2');
c.addEventListener('click',function () {
document.querySelector("input").remove();
});
var d = document.getElementById('btn3');
d.addEventListener('click', function () {
var arr = [];
var items = document.querySelectorAll('input');
for (var i = 0; i<items.length; i++) {
console.log(arr.push(items.value))
}
});Run Code Online (Sandbox Code Playgroud)
h1{
text-align: center;
}
#container input{
margin-bottom: 20px;
border: 2px solid blue;
}
#container input:nth-of-type(odd) {
border: 2px solid red;
}
#container{
width: 25%;
margin: auto;
}
button{
display: …Run Code Online (Sandbox Code Playgroud)