如何獲取jQuery中的屬性值?


獲取 jQuery 中的屬性值非常容易,為此,使用jQuery attr() 方法。您可以嘗試執行以下程式碼以瞭解如何在 jQuery 中獲取屬性值 −

示例

動態演示

<html>

   <head>
      <title>jQuery Example</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

      <script>
      $(document).ready(function(){
         $("button").click(function(){
            alert($("img").attr("height"));
         });
      });
      </script>
   </head>
   
   <body>
      <img src="/green/images/logo.png" alt="logo" width="350" height="120"><br>
      <button>Get the height</button>
   </body>
   
</html>

更新時間:2020-02-13

2K+ 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.