HTML DOM images 集合
 Document 对象
 Document 对象
定义和用法
images 集合返回当前文档中所有图片的数组。
语法
document.images[].property
浏览器支持





所有主要浏览器都支持 images 集合
实例
实例 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="codexy1" border="0" src="klematis.jpg" width="150" height="113">
<img id="codexy2" 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="codexy1" border="0" src="klematis.jpg" width="150" height="113">
<img id="codexy2" border="0" src="klematis2.jpg" width="152" height="128">
<p>第一个图像的ID:
<script>
document.write(document.images[0].id);
</script></p>
</body>
</html>
以上实例输出结果:
第一个图像的ID:codexy1
尝试一下 »
 Document 对象
 Document 对象			
						
			
 JavaScript 教程
JavaScript 教程 JavaScript 对象
JavaScript 对象 jQuery 教程
jQuery 教程 JSON 教程
JSON 教程 AngularJS 教程
AngularJS 教程 Angular 2 教程
Angular 2 教程 Vue.js 教程
Vue.js 教程 React 教程
React 教程 jQuery UI 教程
jQuery UI 教程 jQuery EasyUI 教程
jQuery EasyUI 教程 AJAX 教程
AJAX 教程 Highcharts 教程
Highcharts 教程 Google Maps API 教程
Google Maps API 教程 ES6 教程
ES6 教程 TypeScript教程
TypeScript教程 ES6 标准入门
ES6 标准入门