<!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);
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 1em;
}
button {
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
font-size: 1em;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h1>Dynamic Form Generation</h1>
<form id="dynamicForm">
<div class="form-group">
<label for="numFields">Number of fields</label>
<input type="number" id="numFields" min="1" max="10" value="1">
</div>
<button type="button" onclick="generateFields()">Generate Fields</button>
</form>
<div id="formFields"></div>
</div>
<script>
function generateFields() {
const numFields = document.getElementById('numFields').value;
const formFields = document.getElementById('formFields');
formFields.innerHTML = '';
for (let i = 0; i < numFields; i++) {
const input = document.createElement('input');
input.type = 'text';
input.placeholder = `Field ${i + 1}`;
formFields.appendChild(input);
}
}
</script>
</body>
</html>
标签:formFields,color,表单,生成,font,5px,input,动态,border
From: https://blog.51cto.com/u_16215583/12038956