<form id="form" method="post">
<input type="text" name="sonuc1" id="sonuc1" placeholder="1.Sonuç">
<button type="submit">Ekle</button>
</form>
我想要实现的基本上是,如果 sonuc1 输入为“否”,则添加另一个名为“sonuc2”的输入元素在提交之前
<form id="form" method="post">
<input type="text" name="sonuc1" id="sonuc1" placeholder="1.Sonuc" />
<button type="submit">Ekle</button>
</form>
<script>
document.getElementById("sonuc1").addEventListener("change", function () {
if (this.value.toUpperCase() === "NO") {
var newInput = document.createElement("input");
newInput.type = "text";
newInput.name = "sonuc2";
newInput.placeholder = "2.Sonuc";
document
.getElementById("form")
.insertBefore(newInput, document.querySelector("button"));
}
});
</script>