如何使用 JavaScript 返回文件中的圖片數量?


要返回文件中的影像數量,請使用 JavaScript 中的 images 屬性。

示例

你可以嘗試執行以下程式碼來獲取影像數量 −

現場演示

<!DOCTYPE html>
<html>
   <body>
      <img src="https://tutorialspoint.tw/html5/images/html5-mini-logo.jpg">
      <img src="https://tutorialspoint.tw/hive/images/hive-mini-logo.jpg">
      <img src="https://tutorialspoint.tw/sas/images/sas-mini-logo.jpg">
      <img src="https://tutorialspoint.tw/maven/images/maven-mini-logo.jpg">
      <script>
         var val = document.images.length;
         document.write("<br>Number of images in the document: "+val);
      </script>
   </body>
</html>

更新於: 23-Jun-2020

918 次瀏覽

開啟你的 職業

完成課程獲得認證

立即開始
廣告
© . All rights reserved.