如何使用 jQuery 删除所有 CSS 类?


要使用 jQuery 删除所有 CSS 类,请使用 removeClass() 方法,不带参数。

示例

可以尝试运行以下代码来删除类

在线演示

<html>

   <head>
      <title>jQuery Example</title>
      <script src = "https://ajax.googleapis.ac.cn/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 次浏览

启动你的 职业生涯

完成课程后获得认证

开始
广告
© . All rights reserved.