可以通过JavaScript来动态地创建表单元素并为其添加属性。以下是一个示例:
<!DOCTYPE html><html><head> <title>动态表单</title></head><body><form id="myForm"> <label for="name">姓名:</label> <input type="text" id="name" name="name"><br><br></form><button onclick="addInput()">添加输入框</button><script>function addInput() { var form = document.getElementById("myForm"); var input = document.createElement("input"); input.type = "text"; input.name = "newInput"; form.appendChild(input);}</script></body></html>在上面的示例中,当点击按钮时,会动态地在表单中添加一个输入框。你也可以根据自己的需求添加更多的表单元素,并为其设置不同的属性。


