js獲取頁面中圖片的總數


查看效果:http://keleyi.com/keleyi/phtml/image/9.htm

下面是完整代碼:

<html>
<body>
<div id="keleyiimagescount" style="background:url(http://keleyi.com/keleyi/phtml/picnext/images/k05.jpg);width:550px;height:380px;"></div>
<img border="0" src="http://keleyi.com/image/a/tvh00n12.jpg" />
<img border="0" src="http://keleyi.com/keleyi/phtml/picnext/images/k03.jpg" />
<br /><br />
本頁中圖片的總數是:<span id="keleyiimagesnum"></span>
<script type="text/javascript">
window.onload = function () {
document.getElementById("ke"+"leyiimagescount").innerHTML="<img src='http://keleyi.com/keleyi/phtml/picnext/images/k01.gif' />";
document.getElementById("kel"+"eyiimagesnum").innerHTML=document.images.length;
}
</script>
</body>
</html>


效果如下:

 



本頁中圖片的總數是:

你能全部找到嗎?

總結:使用document.images.length可以獲取頁面中圖片的總數,包括使用javascript加入的圖片,但是css定義的背景圖片不算

原文:http://keleyi.com/a/bjac/ovyge49k.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM