码迷,mamicode.com
首页 > Web开发 > 详细

jquery事件的发布订阅

时间:2016-12-10 16:11:00      阅读:759      评论:0      收藏:0      [点我收藏+]

标签:技术分享   lan   javascrip   事件   http   oct   text   src   charset   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

</head>
<script
 src="http://code.jquery.com/jquery-latest.js"></script>
<body>
<script type="text/javascript"> 

(function($) {
      var o = $({});
      $.subscribe = function() {
          o.on.apply(o, arguments);
      };
      $.unsubscribe = function() {
          o.off.apply(o, arguments);
      };
      $.publish = function() {
          o.trigger.apply(o, $.makeArray(arguments));
      };
})(jQuery);

//订阅
$.subscribe("test", function(e, a1, a2, a3, a4) {
  console.log(e.type + "," + a1 + "," + a2 + "," + a3 + "," + a4);
});

//发布
$.publish("test", ["a", "b", "c", "d"]);

</script>


</script>
</html>

 技术分享

jquery事件的发布订阅

标签:技术分享   lan   javascrip   事件   http   oct   text   src   charset   

原文地址:http://www.cnblogs.com/taoxiaodan/p/6155836.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!