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
»をお試しください
ドキュメントオブジェクト