document.images
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
语法
var imageCollection = document.images;
值
一个 HTMLCollection
,提供了包含在该文档中的所有 images 元素实时的列表。集合中的每条代表了一个单 image 元素的HTMLImageElement
备注
你可以在返回的结果中使用 JavaScript 数组符号 ('[]',译注),或者item()
方法去获取集合中的每个元素。下面方法是等价的:
js
firstImage = imageCollection.item(0);
firstImage = imageCollection[0];
例子
该例是一次通过遍历图片列表找到名称为"banner.gif"
的图片。
js
var ilist = document.images;
for (var i = 0; i < ilist.length; i++) {
if (ilist[i].src == "banner.gif") {
// 发现了 banner 图片
}
}
规范
Specification |
---|
HTML # dom-document-images-dev |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
images |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.