2 回答
TA贡献1856条经验 获得超5个赞
此代码克隆 div N 次
<html>
<body>
<div class="tab" id="id0">
<p>Test Tab</p>
</div>
<script>
// Get the element
var elem = document.querySelector('#id0');
//set n to the value form the previous page
var n = 10;
var i;
for (i = 1; i < n; i++) {
// Create a copy of it
var clone = elem.cloneNode(true);
// Update the ID
clone.id = "id" + n;
// Inject it into the DOM
elem.after(clone);
}
</script>
</body>
</html>
TA贡献1802条经验 获得超5个赞
您可以占用一个 for 并重复您使用 POST 或 GET 带来的步骤数的 div
<!-- One "tab" for each step in the form: -->
<?php
$divs = $_POST('number_divs');
for ($i = 1; $i <= $divs; $i++) {
?>
<div class="tab">
<h1>Register:</h1>
Name:
<p><input placeholder="First name..." oninput="this.className = ''" name="fname"></p>
<p><input placeholder="Last name..." oninput="this.className = ''" name="lname"></p>
</div>
<?php } ?>
- 2 回答
- 0 关注
- 131 浏览
添加回答
举报