<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\" =\"return false\">
</form>
<form name=\"form3\" method=\"post\" action=\"\">
<input type=\"checkbox\" name=\"checkbox\" value=\"checkbox\">
</form>
<button =\"function1()\">Click here</button>
< language=\" \">
function function1() {
var m = document.forms.length;
console.log(\"There are \"+m+\" forms in this document\")
}
</ >
</body>
</html>
本实例中,我们创建了3个form表单,然后使用js的document.forms.length来获取表单个数,最后在控制台中输出这个值。最终输出结果为“There are 3 forms in this document”。
你可以把代码复制到这个页面运行一下。
继续阅读与本文标签相同的文章
上一篇 :
php 表单提交给本页
-
剧情反转?美企主动购买华为5G技术,华为成赞赏排行榜第一名!
2026-05-14栏目: 教程
-
城市数字化后,新一代内生安全系统可全方位保护
2026-05-14栏目: 教程
-
谷歌也来“唱衰”5G,5G手机只会徒增功耗?为何这么说?
2026-05-14栏目: 教程
-
量子信息和量子技术白皮书合肥宣言在中科大发布
2026-05-14栏目: 教程
-
微信悄悄更新一新功能,来看看!
2026-05-14栏目: 教程
