jquery die() method


  Translation results:

die

英[daɪ] 美[daɪ]

vt.& vi. Death, extinguishing; withering, withering; desire, hope

n.Steel type, die; dice

jquery die() methodsyntax

Function: The die() method removes all one or more event handlers added to the specified element through the live() method.

Syntax: $(selector).die(event,function)

Parameters:

##

jquery die() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("p").live("click",function(){
    $(this).slideToggle();
  });
  $("button").click(function(){
    $("p").die();
  });
});
</script>
</head>
<body>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>
<p>请点击任意 p 元素,段落会消失。包括本段落。</p>
<button>移除通过 live() 方法向 p 元素添加的事件处理程序</button>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

ParametersDescription
event Required. Specifies one or more event handlers to be removed. Multiple event values ​​separated by spaces. Must be a valid event.
function Optional. Specifies specific functions to be removed.