语法
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. |
浏览器兼容性
BCD tables only load in the browser
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.