Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / jQuery自定义事件实现例子

一、需求原因虽然JQuery为我们定义了许多的事件,但是有时候还是不能满足我们的要求,故本例实现一个自定义事件实现的例子。二、具体实现<!DOCTYPE html PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type"content="text/html; charset=UTF-8"><title>自定义事件</title><script language="JavaScript"src="../jQuery/jquery-1.7.1.min.js"></script><script type="text/javascript">     $(function(){         $("#btn").bind("myClick",function(){              $("#test").append("自定义事件").append($("<br>"));         });         $("#btn").click(function(){              $(this).trigger("myClick");         });     });</script></head><body>     <input id="btn" type="button" value="点我">     <div id="test"></div></body></html>三、运行结果