小白教程
所有教程
关于
Search
172.70.127.159
172.70.127.159
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Event undelegate”的源代码
本页内容
上一节:
Event_unbind
下一节:
Event_unload
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:undelegate()}}[[Category:jquery ref events|57]] = jQuery undelegate() 方法 = [[jquery ref events|jQuery 事件方法]] 通过 undelegate() 方法从所有元素移除所有事件处理程序: <sample title="" desc="" lang="html" hererun="1"> $("body").undelegate(); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("body").delegate("p","click",function(){ $(this).slideToggle(); }); $("button").click(function(){ $("body").undelegate(); }); }); </script> </head> <body> <p>这是一个段落。</p> <p>这是另外一个段落。</p> <p>点击任意段落(p 元素),该段落就会消失。</p> <button>使用 delegate() 方法移除所有段落(p 元素)的事件句柄</button> </body> </html> </run> == 定义和用法 == undelegate() 方法移除一个或多个由 [[event delegate|delegate()]] 方法添加的事件处理程序。 自 jQuery 版本 1.7 起,[[event on|on()]] 和 [[event off|off()]] 方法是添加和移除元素上的事件处理程序的首选方法。 == 语法 == <pre> $(selector).undelegate(selector,event,function) </pre> {| class="table table-striped table-hover" ! 参数 ! 描述 |- | selector | 可选。规定需要删除事件处理程序的选择器。 |- | event | 可选。规定需要删除处理函数的一个或多个事件类型。 |- | function | 可选。规定要删除的具体事件处理函数。 |} == 更多实例 == [[try.php?filename=tryjquery_event_undelegate_event|移除所有 click 事件处理程序]] 如何使用 undelegate() 方法来移除所有 <p> 元素上的 click 事件处理程序。 [[try.php?filename=tryjquery_event_undelegate_func|移除由 delegate() 添加的指定函数]] 如何使用 undelegate() 方法只移除指定函数。 [[jquery ref events|jQuery 事件方法]]
返回至“
Event undelegate
”。
上一节:
Event_unbind
下一节:
Event_unload