HTML DOM images 集合

2018-12-02 14:04 更新

HTML DOM images 集合

Document 對象參考手冊 Document 對象

定義和用法

images 集合返回當前文檔中所有圖片的數(shù)組。

語法

document.images[].property


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 images 集合


實例

實例 1

返回文檔的圖片數(shù):

<html>
<body>

<img border="0" src="klematis.jpg" width="150" height="113">
<img border="0" src="klematis2.jpg" width="152" height="128">

<p>Number of images:
<script>
document.write(document.images.length);
</script></p>

</body>
</html>

以上實例輸出結(jié)果:

Number of images: 2

嘗試一下 ?

實例 2

返回文檔中的第一張圖片:

<html>
<body>

<img id="klematis lilac" border="0" src="klematis.jpg" width="150" height="113">
<img id="klematis pink" border="0" src="klematis2.jpg" width="152" height="128">

<p>Id of first image:
<script>
document.write(document.images[0].id);
</script></p>

</body>
</html>

以上實例輸出結(jié)果:

Id of first image: klematis lilac

嘗試一下 ?


Document 對象參考手冊 Document 對象
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號