js 自动添加任意数量的表单内容

xiaoxiao2022-06-12  28

<html><script language="javascript">var i =2;//设置基数为2function addFile(){var dv = document.getElementById("dvFiles");//设置生成表单内容的容器,即放置位置var file = document.createElement("input");//建立input标记的内容file.type = "text";//设置类型file.id = file.name = "image" + i;//设置id和名称dv.appendChild(file);//在容器里添加var btn = document.createElement("input");//建立input标记内容btn.type = "button";//类型btn.id = btn.name="btn"+i;//id和名称btn.value = "删除";//内容值btn.onclick = function() {//单击调用函数 var b = document.getElementById(btn.id);//获得相关内容dv.removeChild(b.nextSibling); //remove <BR>//删除dv.removeChild(b.previousSibling); //filedv.removeChild(b); //btn} dv.appendChild(btn);dv.appendChild(document.createElement("BR")); //打印换行}

</script>

<body><input type="text" name="image1" /><div id="dvFiles"></div><input type="button" name="Submit" value="添加上传" onClick="addFile()"></body>

</html>

转载请注明原文地址: https://www.6miu.com/read-4933932.html

最新回复(0)