<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{ margin: 0; padding: 0; } .father{ width: 200px; height: 200px; background: red; } .son{ width: 100px; height: 100px; background: blue; } </style> <script src="./jquery-1.10.1.min.js"></script> </head> <body> <script> $(function() { //事件命名空间类似css的类,我们在事件类型的后面通过点加名称的方式来给事件添加命名空间: /* 想要事件的命名空间有效,必须满足两个条件 1.事件是通过on来绑定的 2.通过trigger触发事件 */ $(".son").on("click.zs",function() { alert("666"); }); $(".son").on("click.ls",function() { alert("666666"); }); $(".son").trigger("click.ls"); /*核心在于*/ //能够让相同的点击事件找到想执行的哪一个点 }); </script> <div class="father"> <div class="son"></div> </div> <a href="http://www.baidu.com"><span>注册</span></a> <form action="http://www.taobao.com"> <input type="text"> <input type="submit"> </form> </body> </html>
jQuery第二十八篇 事件命名空间
关注
打赏