<!DOCTYPE html> <html> <body> <h1>Document 对象</h1> <h2>forms 属性</h2> <form> <p>名字:<input type="text" name="fname" value="Gates"></p> <p>姓氏:<input type="text" name="lname" value="Bill"></p> </form> <p>文档中表单元素的数量是:</p> <p id="demo"></p> <script> let num = document.forms.length; document.getElementById("demo").innerHTML = num; </script> </body> </html>