jquery自定义事件要用到2个方法

1:bind(type,[data],fn);其中type是自定义事件类型(名称);data是可选参数,是自定义函数fn中第一个参数中的data属性,注意data是一个数组类型;fn是事件触发时执行的函数。

2:trigger(type,[data]);其中type是自定义事件类型(名称);data是可选参数是自定义函数fn中第二个参数,注意这是一个数组类型。

应用举例:

<!doctypehtml><htmllang="zh"><head><metacharset="UTF-8"><metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/><title>Document</title><metahttp-equiv="X-UA-Compatible"content="IE=edge,chrome=1"><metaname="renderer"content="webkit|ie-comp|ie-stand"><metaname="keywords"content=""><metaname="description"itemprop="description"content=""><metaname="protocol"content="1"><metaitemprop="name"content="name"><metaitemprop="p_w_picpath"content="https://cache.yisu.com/upload/information/20200311/55/213636.jpg"/><linkrel="dns-prefetch"href="http://7.url.cn"><linkrel="dns-prefetch"href="http://9.url.cn"><linkrel="dns-prefetch"href="http://8.url.cn"><linkrel="stylesheet"href="http://8.url.cn/edu/css/common.980ee.css"/><linkrel="stylesheet"href="http://8.url.cn/edu/css/index_refactor.90164.css"/><linkrel="shortcuticon"href="http://9.url.cn/edu/img/favicon.ico"/></head><body><div><p><inputtype="text"id="number01"value="0">&nbsp;&nbsp;+</p><p><inputtype="text"id="number02"value="1">&nbsp;&nbsp;<inputtype="button"id="ok"value="="></p><p><inputtype="text"id="result"value="1">&nbsp;&nbsp;</p></div><scripttype="text/javascript"src="js/jquery.js"></script><scripttype="text/javascript"><!--$(window).bind("resultChange",function(event,a,b,c){alert(a+":"+b+":"+c);});$("#result").change(function(){varresult=$(this).val();if(result>0)$(window).trigger("resultChange",[result,result,result]);});$("#ok").click(function(){$("#result").val(($("#number01").val()-0)+($("#number02").val()-0));$("#result").change();});//--></script></body></html>