form表单动态添加元素,如何用DOM读取出来

来源:百度知道 编辑:UC知道 时间:2024/06/02 14:01:24

<html>
<head>
<meta http-equiv=content-type content="text/html;charset=GBK">
</head>
<body>
<form name="fm">
</form>
<input id="btn3" type="button" value="填充form表单" onclick="fill()">
<input id="btn2" type="button" value="获得填充后的结果" disabled onclick="control()">
</body>
<script>
function fill(){// 动态填充你的form表单
var form = document.forms[0];
if(!form) return;

var input_txt = document.createElement("input");
input_txt.type = "text";
input_txt.name = "tmp";
form.appendChild(input_txt);

var btn = document.getElementById("btn2");
btn.disabled = false;
}

function control(){// 获得你新添加的元素
var form = document.for