首页javascriptformJavascript Form - 如何获取在当前页面中使用表单长度属性创建的表单元素的数量

Javascript Form - 如何获取在当前页面中使用表单长度属性创建的表单元素的数量

我们想知道如何获取在当前页面中使用表单长度属性创建的表单元素的数量。


<html>
<body>
<form name="form1" method="post" action="">
    <input type="text" name="textfield">
</form>
<form name="form2" method="post" action="">
    <input type="button" value="Only a sample button" onclick="return false"> 
</form>
<form name="form3" method="post" action="">
    <input type="checkbox" name="checkbox" value="checkbox">
</form>
<button onclick="function1()">Click here</button>
<script language="JavaScript">
function function1() {
    var m = document.forms.length;
    console.log("There are "+m+" forms in this document") 
} 
</script>
</body>
</html>