当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery自定义事件的简单实现代码

jQuery自定义事件的简单实现代码

2019年03月21日  | 移动技术网IT编程  | 我要评论

一、需求原因
虽然jquery为我们定义了许多的事件,但是有时候还是不能满足我们的要求,故本例实现一个自定义事件实现的例子。

二、具体实现

代码如下:


<!doctype html public "-//w3c//dtdhtml 4.01 transitional//en" "https://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="点我">
     <p id="test"></p>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网