.die()
.die() 返回: jQuery
描述: 從元素中刪除先前用.live()綁定的所有事件
version added: 1.4.1.die()
任何通過.live()附加的處理器都可以使用.die()刪除。這個(gè)方法類似于調(diào)用不帶參數(shù)的.unbind(),這是用來刪除先前用.bind() 綁定的所有事件。見.live()和.unbind()討論的更多詳情。
.die( eventType, [ handler ] ) Returns: jQuery
描述: 從元素中刪除一個(gè)先前用.live()綁定的事件。
-
version added: 1.3.die( eventType, [ handler ] )
eventType一個(gè)包含一個(gè)或多個(gè)JavaScript事件類型的字符串,比如"click"或"keydown,"或自定義事件的名稱。
handler不再執(zhí)行的函數(shù)。
任何通過.live()附加的處理器都可以使用.die()刪除。 這個(gè)方法類似于.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: 通過作為第二個(gè)參數(shù)的函數(shù),只解除以前綁定的這個(gè)處理程序:
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.