下面的JS代碼通過document.forms數組獲得網頁中表單(form)的數量
<!DOCTYPE html>
<html>
<body>
<h1>sharejs.com</h1>
<form name="Form1"></form>
<form name="Form2"></form>
<form></form>
<p>Number of forms:
<script>
document.write(document.forms.length);
</script></p>
</body>
</html>
運行結果如下:
Number of forms: 3
更多信息請查看IT技術專欄