HTML DOM images collection
Document Object
Définition et utilisation
images collection Renvoie un tableau de toutes les images dans le document en cours.
grammaire
document.images[].property
support du navigateur
Tous les principaux navigateurs prennent en charge les images collection
Exemples
exemple 1
Retour au numéro de document de photos:
<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>
Des exemples de sortie ci-dessus:
图像数目: 2
Essayez »
exemple 2
Renvoie la première image dans le document:
<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>
Des exemples de sortie ci-dessus:
第一个图像的ID:w3big1
Essayez »
Document Object