document.images

Document 接口的只读属性images返回当前文档中所有 image 元素的集合.

语法

var imageCollection = document.images;

一个 HTMLCollection,提供了包含在该文档中的所有images元素实时的列表。 集合中的每条代表了一个单image元素的HTMLImageElement

备注

你可以在返回的结果中使用JavaScript 数组符号('[]',译注),或者item() 方法去获取集合中的每个元素。下面方法是等价的:

firstImage = imageCollection.item(0);

firstImage = imageCollection[0];

例子

该例是一次通过遍历图片列表找到名称为"banner.gif"的图片。

var ilist = document.images;
for(var i = 0; i < ilist.length; i++) {
    if(ilist[i].src == "banner.gif") {
         // 发现了banner图片
    }
}

规范

Specification Status Comment
HTML Living Standard
Document.images
Living Standard  
Document Object Model (DOM) Level 2 HTML Specification
Document.images
Obsolete Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
imagesChrome Full support 1Edge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown