gpt4 book ai didi

javascript - 如何删除旧文本框,保存用户输入数据,同时添加新文本框 onclick?

转载 作者:行者123 更新时间:2023-12-02 16:07:50 25 4
gpt4 key购买 nike

如何删除旧的文本框并保存用户输入,同时添加新的文本框 onclick?我希望用户能够添加新页面,而不显示旧页面。

<html>
<head>
<script>
var boxCount=1;
var boxName=0;
function newBox(){
var input=document.createElement("input");
input.type="text"
input.name="fname_"+boxCount;
input.placeholder="fname_"+boxCount;
document.getElementById('box').appendChild(input);
var new_line=document.createElement("br");document.getElementById('box').appendChild(new_line);
var new_line2=document.createElement("br");document.getElementById('box').appendChild(new_line2);

boxCount++;
}
</script>
<head>
<body>
<button type="button" onclick="newBox()">Add Property</button><br/>
<form action="#" method="post">
<br/><span id="box"></span><br/><br/>
<input type="submit" value="Submit">
</form>
</body>
</html>

最佳答案

您可以尝试将之前每个输入的类型设置为隐藏
见下文:

var input,
inputCount = 0;

function newInput () {
if (input !== undefined) {
input.type = "hidden";
}
inputCount++;

input = document.createElement("input");
input.type = "text";
input.name = input.placeholder = "fname" + inputCount;
document.getElementById("box").appendChild(input);
}
<button type="button" onclick="newInput()">Add Property</button><br/>
<form action="#" method="post">
<br/><span id="box"></span><br/><br/>
<input type="submit" value="Submit">
</form>

关于javascript - 如何删除旧文本框,保存用户输入数据,同时添加新文本框 onclick?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30552749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com