<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
background-color: #f0f2f5;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
button {
padding: 10px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
font-size: 1em;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input, .form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Dynamic Form</h1>
<form id="dynamicForm">
<div id="formFields">
<!-- Dynamic fields will be added here -->
</div>
<button type="button" onclick="addField()">Add Field</button>
</form>
</div>
<script>
let fieldCount = 0;
function addField() {
fieldCount++;
const formFields = document.getElementById('formFields');
const newField = document.createElement('div');
newField.className = 'form-group';
newField.innerHTML = `
<label for="field${fieldCount}">Field ${fieldCount}</label>
<input type="text" id="field${fieldCount}" name="field${fieldCount}" placeholder="Enter value">
`;
formFields.appendChild(newField);
}
</script>
</body>
</html>
标签:25,group,form,示例,color,margin,表单,5px,border
From: https://blog.51cto.com/u_16160172/12062277