HTML DOM คอลเลกชันภาพ
ความหมายและการใช้งาน
คอลเลกชันภาพส่งกลับอาร์เรย์ของภาพทั้งหมดในเอกสารปัจจุบัน
ไวยากรณ์
document.images[].property
สนับสนุนเบราว์เซอร์
เบราว์เซอร์ที่สำคัญทุกการสนับสนุนของคอลเลกชันภาพ
ตัวอย่าง
ตัวอย่างที่ 1
ย้อนกลับไปยังเลขที่เอกสารของภาพ:
<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>
ตัวอย่างของการส่งออกดังกล่าวข้างต้น:
图像数目: 2
ลอง»
ตัวอย่างที่ 2
ผลตอบแทนที่ได้ภาพแรกในเอกสาร:
<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>
ตัวอย่างของการส่งออกดังกล่าวข้างต้น:
第一个图像的ID:w3big1
ลอง»
วัตถุเอกสาร