下面的JS代碼通過document.forms數(shù)組獲得網(wǎng)頁中表單(form)的數(shù)量
<!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>
運(yùn)行結(jié)果如下:
Number of forms: 3
更多信息請查看IT技術(shù)專欄