DOM colección de imágenes HTML
Definición y Uso
colección de imágenes Devuelve una matriz de todas las imágenes en el documento actual.
gramática
document.images[].property
Soporte para el navegador
Todos los principales navegadores soportan colección de imágenes
Ejemplos
Ejemplo 1
Volver al número de cuadros:
<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>
Los ejemplos de la salida anterior:
图像数目: 2
Trate »
Ejemplo 2
Devuelve la primera imagen en el documento:
<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>
Los ejemplos de la salida anterior:
第一个图像的ID:w3big1
Trate »
objetos del documento