<html> <body> <script language="JavaScript"> function showNumElements(){ console.log("There are " + document.form1.length + " elements in this document"); } </script> <form name="form1"> Enter First Name: <input type="text" size=15><br> Enter Last Name: <input type="text" size=20><br> Enter address: <input type="text" size=40><br><br> <input type="button" value="Submit" onClick=showNumElements()> </form> </body> </html>
首先获取表单对象,然后通过length属性获取表单元素的个数。输出结果为:“there are 4 elements in this document”。
你可以把代码复制到这个页面运行一下。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号