用AI赚第一桶💰低成本搭建一套AI赚钱工具,源码可二开。 广告
[TOC] ## .off() 移除一个事件处理函数 ### 语法 ``` .off( events [, selector ] [, handler(eventObject) ] ) ``` ### 示例 #### 移除所有事件 ``` $("p").off() ``` #### 移除所有段落上的代理事件 ``` $("p").off( "click", "**" ) ``` #### 仅移除先前绑定的事件处理函数 ``` var foo = function () { // code to handle some kind of event }; // ... now foo will be called when paragraphs are clicked ... $("body").on("click", "p", foo); // ... foo will no longer be called. $("body").off("click", "p", foo); ``` #### 通过指定名字空间,解除绑定表单上所有的代理事件 ``` var validate = function () { // code to validate form entries }; // delegate events under the ".validator" namespace $("form").on("click.validator", "button", validate); $("form").on("keypress.validator", "input[type='text']", validate); // remove event handlers in the ".validator" namespace $("form").off(".validator"); ```