<!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() { /*想要自定义事件, 必须满足两个条件 1.事件必须是通过on绑定的 2.事件必须通过trigger来触发 */ /* $(".son").cyg(function (event) { alert("son"); }); */ $(".son").on("cyg",function()//结果是什么 { alert("son"); }); $(".son").triggerHandler("cyg");//要触发什么 }); </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第二十七篇 自定义事件
关注
打赏