以下是我的HTML:
<div id="mover">
<img src="images/building3.jpg" width="330" height="150" />
<img src="images/building5.jpg" width="330" height="150" />
<img src="images/building1.jpg" width="330" height="150" />
<img src="images/building4.jpg" width="330" height="150" />
</div>
使用:
document.getelementById("mover");
只给我这个div,我如何使用JavaScript从这个div中获取所有图像?
答案 0 :(得分:0)
请告诉我这是否适合您:
<html>
<body>
<div id="mover">
<img src="images/building3.jpg" width="330" height="150" />
<img src="images/building5.jpg" width="330" height="150" />
<img src="images/building1.jpg" width="330" height="150" />
<img src="images/building4.jpg" width="330" height="150" />
</div>
<script>
var imgs = document.getElementById("mover").getElementsByTagName("img");
for (i in imgs) {
if (parseInt(i) > -1) { // check if it is an integer
alert(document.getElementById("mover").getElementsByTagName("img")[i].src);
}
}
</script>
</body>
</html>