Home  >  Article  >  Web Front-end  >  Usage examples of unbind() method in jQuery

Usage examples of unbind() method in jQuery

巴扎黑
巴扎黑Original
2017-06-25 15:17:081409browse

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:

Parameter Description
data The event type to be unbound.
Function The event handler function to unbind from the event of each matching element.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn