首页
极刻
圈子
教程
开源
登录 / 注册
返回教程:jQuery 教程
TRY RUN / 在线示例
jQuery 教程 移除所有 click 事件处理程序
jQuery 教程 移除所有 click 事件处理程序
源代码
运行
<!DOCTYPE html> <html> <head> <script src="//libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> function changeSize() { $(this).animate({fontSize:"+=3px"}); } function changeSpacing() { $(this).animate({letterSpacing:"+=2px"}); } $(document).ready(function(){ $("body").delegate("p","click",changeSize); $("body").delegate("p","click",changeSpacing); $("button").click(function(){ $("body").undelegate("p","click"); }); }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <p>Click any p element to increase size and letterspacing.</p> <button>Remove all "click" event handlers (added with the delegate() method) for all p elements</button> </body> </html>
运行结果