HTML DOM gambar koleksi
Definisi dan Penggunaan
gambar koleksi Mengembalikan sebuah array dari semua gambar dalam dokumen saat ini.
tatabahasa
document.images[].property
Dukungan Browser
Semua browser utama mendukung pengumpulan gambar
contoh
contoh 1
Kembali ke nomor dokumen gambar:
<html>
<body>
<img border="0" src="klematis.jpg" width="150" height="113">
<img border="0" src="klematis2.jpg" width="152" height="128">
<p>图像数目:
<script>
document.write(document.images.length);
</script></p>
</body>
</html>
<body>
<img border="0" src="klematis.jpg" width="150" height="113">
<img border="0" src="klematis2.jpg" width="152" height="128">
<p>图像数目:
<script>
document.write(document.images.length);
</script></p>
</body>
</html>
Contoh output di atas:
图像数目: 2
Coba »
contoh 2
Mengembalikan gambar pertama dalam dokumen:
<html>
<body>
<img id="w3big1" border="0" src="klematis.jpg" width="150" height="113">
<img id="w3big2" border="0" src="klematis2.jpg" width="152" height="128">
<p>第一个图像的ID:
<script>
document.write(document.images[0].id);
</script></p>
</body>
</html>
<body>
<img id="w3big1" border="0" src="klematis.jpg" width="150" height="113">
<img id="w3big2" border="0" src="klematis2.jpg" width="152" height="128">
<p>第一个图像的ID:
<script>
document.write(document.images[0].id);
</script></p>
</body>
</html>
Contoh output di atas:
第一个图像的ID:w3big1
Coba »
Document Object