.die()

Contents:

.die() 官网原E文: jQuery

描述: 从元素中删除先前用.live()绑定的所有事件

  • version added: 1.4.1.die()

任何通过.live()附加的处理器都可以使用.die()删除。这个方法类似于调用不带参数的.unbind(),这是用来删除先前用.bind() 绑定的所有事件。见.live().unbind()讨论的更多详情。

.die( eventType, [ handler ] ) Returns: jQuery

描述: 从元素中删除一个先前用.live()绑定的事件。

  • version added: 1.3.die( eventType, [ handler ] )

    eventType一个包含一个或多个JavaScript事件类型的字符串,比如"click"或"keydown,"或自定义事件的名称。

    handler不再执行的函数。

任何通过.live()附加的处理器都可以使用.die()删除。 这个方法类似于.unbind(),这是用来删除先前用.bind() 绑定的所有事件。见.live().unbind()讨论的更多详情。

Examples:

Example: 彩色按钮可以绑定和取消绑定事件的。

<!DOCTYPE html>
<html>
<head>
  <style>
button { margin:5px; }
button#theone { color:red; background:yellow; }
</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <button id="theone">Does nothing...</button>
<button id="bind">Bind Click</button>
<button id="unbind">Unbind Click</button>

<div style="display:none;">Click!</div>
<script>

function aClick() {
  $("div").show().fadeOut("slow");
}
$("#bind").click(function () {
  $("#theone").live("click", aClick)
              .text("Can Click!");
});
$("#unbind").click(function () {
  $("#theone").die("click", aClick)
              .text("Does nothing...");
});

</script>

</body>
</html>

Demo:

Example: 所有段落解除绑定的live事件,写:

$("p").die()

Example: 所有段落解除绑定的live click事件,写:

$("p").die( "click" )

Example: 通过作为第二个参数的函数,只解除以前绑定的这个处理程序:

var foo = function () {
// code to handle some kind of event
};

$("p").live("click", foo); // ... now foo will be called when paragraphs are clicked ...

$("p").die("click", foo); // ... foo will no longer be called.
jQuery 1.6 API 中文版Clove整理、修订