js 中 getElementsByTagName 的用法

<html>
<body>
<img id="compman" src="compman.gif" alt="Computerman" />
<br />

<script type="text/javascript">
x=document.getElementsByTagName('img')[0];
document.write("Image id: " + x.id
);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('compman').id
);
</script>

</body>
</html>

相关推荐