<html>
<head>
<script type="text/javascript">
function getElements()
{
var x = document.getElementsByTagName("input");
alert("一共有 "+x.length+" 个 input 元素");
}
</script>
</head>
<body>
<p>请选择要删除的数据:
<input type="checkbox" name="aid" value="1" />1
<input type="checkbox" name="aid" value="2" />2
<input type="checkbox" name="aid" value="3" />3
<input type="checkbox" name="aid" value="4" />4
<input type="checkbox" name="aid" value="5" />5
<button onclick="getElements()">确定</button>
</p>
</body>
</html>
运行该例子,点击确认按钮,会弹出提示框并打印出:一共有 5 个 input 元素。