我使用 HTML、JS 创建了一个表单。当前表单无法在其内部创建子表单。它可以解释为想象一个动态表,我们创建一个按钮,单击该按钮以创建新行。同样,我想创建一个按钮,在它周围的静态表单中添加一个表单(文本框、下拉菜单、丰富的内容编辑器、表格等)。
我尝试创建 velocimacro,但随后意识到无法在函数中调用宏。我尝试在 Javascript 中创建表单,但无法创建几个字段。
预期结果:该按钮将能够在单击时将子表单添加到原始表单。
我使用 HTML、JS 创建了一个表单。当前表单无法在其内部创建子表单。它可以解释为想象一个动态表,我们创建一个按钮,单击该按钮以创建新行。同样,我想创建一个按钮,在它周围的静态表单中添加一个表单(文本框、下拉菜单、丰富的内容编辑器、表格等)。
我尝试创建 velocimacro,但随后意识到无法在函数中调用宏。我尝试在 Javascript 中创建表单,但无法创建几个字段。
预期结果:该按钮将能够在单击时将子表单添加到原始表单。
我真的希望你能读懂大安的建议。
无论如何,这是一个小品尝者。如果您想要创建更多不同的元素,我建议您使用 Google。
function createNewForm(form) {
newForm = document.createElement('form');
input = document.createElement('input');
input.type = "text";
input.value = "new text input";
button = document.createElement('button');
button.type = "button";
button.innerText = "new button";
newForm.appendChild(input);
newForm.appendChild(button);
form.appendChild(newForm);
console.log(form);
}
<form action="">
<input type="text" value="hello">
<button type="button" onclick="createNewForm(this.form)">create form</button>
</form>