Home > Web Front-end > JS Tutorial > body text

jQuery: Detailed explanation of the use of die()

黄舟
Release: 2017-06-26 09:38:15
Original
1609 people have browsed it

This article mainly introduces the usage of the die() method in jQuery. The example analyzes the function, definition and removal of all the die() method added to the specified element through the live() method. For tips on using multiple event handling programs, friends in need can refer to

This article explains the usage of the die() method in jQuery with examples. Share it with everyone for your reference. The specific analysis is as follows:

This method removes all one or more event handlers added to the specified element through the live() method.

Syntax structure:

$(selector).die(type,function)
Copy after login

Parameter list:

实例代码:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>脚本之家</title>
<style type="text/css">
p{border:1px solid blue;}
li 
{
  
list-style-type
:none;
  width:150px;
  height:150px;
  border:1px solid green;
}
</style>
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript"> 
$(
document
).ready(function(){ 
  $("p").live("click",function(){ 
    $("li").slideToggle(); 
  }); 
  $("button").click(function(){ 
    $("p").die(); 
  }); 
}) 
</script>
</head>
<body>
<p>
  <ul>
    <li>脚本之家</li>
  </ul>
</p>
<button>删除添加</button>
</body>
</html>
Copy after login

概述

从元素中删除先前用.live()绑定的所有事件.(此方法与live正好完全相反。)

如果不带参数,则所有绑定的live事件都会被移除。

你可以解除用live注册的自定义事件。

如果提供了type参数,那么会移除对应的live事件。

如果也指定了第二个参数function,则只移出指定的事件处理函数。

参数

type[,fn] String,FunctionV1.3

type:要移除的一个或多个事件处理程序。由空格分隔多个事件值。必须是有效的事件。

fn:要移除的函数。。

type StringV1.4.3

要移除的一个或多个事件处理程序。 由空格分隔多个事件值。必须是有效的事件。

示例

描述:

给按钮解除click事件

jQuery 代码:

function aClick() { $("div").show().fadeOut("slow"); } $("#unbind").click(function () { $("#theone").die("click", aClick) });
Copy after login

The above is the detailed content of jQuery: Detailed explanation of the use of die(). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
ParametersDescription
##type Optional. Defines one or more event types to attach to the element. Multiple event values ​​separated by spaces.
functionDefine the function that runs when an event occurs.