x
 
<!DOCTYPE html>
<html>
<body>
<h1>Document 对象</h1>
<h2>forms 属性</h2>
<form action="/demo/action_page.php">
<p>名字:<input type="text" name="fname" value="Gates"></p>
<p>姓氏:<input type="text" name="lname" value="Bill"></p>
<p>城市:<input type="text" name="city" value="Seattle"></p>
<input type="submit" value="提交">
</form> 
<p>表单中每个元素的值是:</p>
<p id="demo"></p>
<script>
const form = document.forms[0];
let text = "";
for (let i = 0; i < form.length; i++) {
  text += form.elements[i].value + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>