我正在使用document.getElementById.innerHTML
生成一个表单,该表单最后应该具有一个提交按钮。但是该表单具有通过单击按钮添加的可变数量的字段,问题是在添加字段时将其插入到保存按钮下方。
<button class="fontButton" onClick="addField()">+</button>
<form id="tasksDataForm"></form>
<script>
var f = document.getElementById("tasksDataForm");
function addField() {
var tasksDataFields = `<br/> <input type="text"> <br/>`;
<!-- I have to put this button to end of the form and all fields that are added to form should be inserted above it -->
if(tasks.innerHTML == ''){
tasks.innerHTML += '<input type="submit" value="Save">';
}
tasks.innerHTML += tasksDataFields;
}
</script>
答案 0 :(得分:0)
感谢兰迪·卡斯伯恩(Randy Casburn)的建议,它成功了。
char