我想在单击按钮时将框数从1框增加到(框数)。如果有人可以帮助我,请。 这是我的代码
<section>
<h2>Click the below button to add boxes</h2>
<div class="sbutton">
<p><a id="boxes2">click here!</a></p>
</div>
<div id="box2"></div>
</section>
CSS
#box2{
float: left;
width: 20px;
height: 20px;
margin: 15px;
border: 2px solid black;
}
.sbutton a{
display: inline;
padding: 20px 20px 40px;
cursor: pointer;
text-decoration: none;
margin: 20px;
justify-items: center;
margin-left: 160px;;
}
JavaScript
var x = document.getElementById("boxes2");
x.addEventListener("click", myFunction);
function myFunction() {
var box = document.createElement('div');
box.classList.add('box2');
document.body.appendChild(box2);
}