jQuery removeAttr()的例子

jQuery removeAttr()的例子

removeAttr()方法是jQuery内置的方法,用于从选定的元素中删除一个或多个属性。

语法:

$(selector).removeAttr(attribute)

参数:此函数接受单参数属性,这是强制性的。它用于指定一个或多个要删除的属性。几个属性可以用空格操作符分开。

返回值:该方法返回带有移除属性的选定元素。

下面的例子说明了jQuery中的removeAttr()方法。

示例:

<!DOCTYPE html>
<html>
   <head>
       <title>The removeAttr Method</title>
       <script src=
       "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
       </script>
        
        <!-- jQuery code to show the working of this method -->
       <script>
            (document).ready(function() {
            ("button").click(function() {
                 $("p").removeAttr("style");
             });
         });
      </script>
      <style>
         div {
             width: 300px;
             min-height: 150px;
             border: 2px solid green;
             padding: 20px;
             text-align:center;
         }
      </style>
   </head>
   <body>
      <div>
         <!-- click on the any of the paragraph
         and see the change -->
         <p style="font-size:35px;font-weight:bold;
                       color:green;">Welcome to</p>
         <p style="font-size:35px;font-weight:bold;
                  color:green;">GeeksforGeeks!.</p>
         <button>Click Here!</button>
      </div>
   </body>
</html>

输出:
jQuery removeAttr()的例子

jQuery是一个开源的JavaScript库,它简化了HTML/CSS文档之间的交互,它以其 “少写多做 “的理念而广为人知。
你可以通过学习这个jQuery教程和jQuery实例,从基础开始学习jQuery。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程