delegate
UK[ˈdelɪgət] US[ˈdɛlɪˌɡet]
n. Representative, delegation member
vt. Appointed representative; authorized to ;[Legal]Debt transfer
jquery undelegate() method syntax
Function: The unelegate() method deletes one or more event handlers added by the delegate() method.
Syntax: $(selector).undelegate(selector,event,function)
##Parameters:
Parameters | Description |
selector | Optional. Specifies the selector that requires event handlers to be removed. |
event | Optional. Specifies one or more event types for which handlers need to be removed. |
function | Optional. Specifies the specific event handler function to be deleted. |
jquery undelegate() method example
<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(){
$("body").delegate("p","click",function(){
$(this).slideToggle();
});
$("button").click(function(){
$("body").undelegate();
});
});
</script>
</head>
<body>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>
<p>点击任何段落可以令其消失。包括本段落。</p>
<button>从所有元素删除由 delegate() 方法添加的事件处理器</button>
</body>
</html>
Run instance »Click the "Run instance" button to view the online instance