如何使用 jQuery 刪除所有 CSS 類?


要使用 jQuery 刪除所有 CSS 類,請使用 removeClass() 方法,不帶引數。

示例

可以嘗試執行以下程式碼來刪除類

線上演示

<html>

   <head>
      <title>jQuery Example</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
   
      <script>
         $(document).ready(function() {
            $("p").removeClass();
         });
      </script>
       
      <style>
         .red {
            color:red;
         }
         .green {
            color:green;
         }
      </style>
   </head>
   
   <body>
      <p class = "red" >This is first paragraph.</p>
      <p class = "green">This is second paragraph.</p>
   </body>
   
</html>

更新時間: 2019 年 12 月 17 日

518 次瀏覽

啟動你的 職業生涯

完成課程後獲得認證

開始
廣告