jQuery removeProp()的应用实例

jQuery removeProp()的应用实例

removeProp()方法是jQuery的一个内置方法,用于删除prop()方法所设置的属性。prop()方法是用来添加属性到一个选定的元素。

语法:

$(selector).removeProp(property)

参数:该方法接受单参数属性,这是强制性的。它用于指定需要删除的属性的名称。

返回值:该方法返回已删除指定属性的选定元素。

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

示例:

<!DOCTYPE html>
<html>
    <head>
        <title>The removeProp 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() {
                    var GFG =("div");
                    GFG.prop("color", "green");
                    GFG.append("The value of color: "
                                     + GFG.prop("color"));
                    GFG.removeProp("color");
                    GFG.append("<br>The value of color after removeProp: " 
                                            +GFG.prop("color") + "<br>");
                });
            });
        </script>
        <style>
            div {
                width: 400px;
                min-height: 60px;
                padding: 15px;
                border: 2px solid green;
                margin-bottom: 10px;
            }
        </style>
    </head>
    <body>
       
        <div></div>
        <!-- click on this button -->
        <button>Click Here!</button>
        <br>
        <br>
    </body>
</html>

输出:
jQuery removeProp()的应用实例

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程