Home >Web Front-end >JS Tutorial >Usage examples of unbind() method in jQuery
This article mainly introduces the usage of the unbind() method in jQuery. The example analyzes the function, definition and removal of the selected element of the unbind() method. Event processing Program usage skills, required Friends can refer to
The example in this article describes the usage of the unbind() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method removes the event handler of the selected element, including custom events registered through the bind() method.
The unbind() method without parameters will delete all bound events.
If this method provides an event type as a parameter, it will only delete the bound event of this type.
If the handler function passed when binding is used as the second parameter, only this specific event handler function will be deleted.
Grammar structure:
The code is as follows:
$(selector).unbind(type,function)
Parameter list:
Example code:
The code is as follows:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.jb51.net/" /> <title>脚本之家</title> <style type="text/css"> p{ width:200px; height:200px; background-color:blue; text-align :center; line-height :200px; } </style> <script type="text/ javascript " src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("p").click(function(){ $("p").append("添加的内容"); }); $("button").click(function(){ $("p").unbind(); }) }) </script> </head> <body> <p></p> <button>删除事件</button> </body> </html>
The above code can be deleted on p Registered event handler function.
The above is the detailed content of Usage examples of unbind() method in jQuery. For more information, please follow other related articles on the PHP Chinese website!