Event Handler 正在参加 2020 年度 OSC 中国开源项目评选,请投票支持!
Event Handler 在 2020 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
投票让它出道
已投票
Event Handler 获得 2020 年度 OSC 中国开源项目评选「最佳人气项目」 !
Event Handler 获得 2020 年度 OSC 中国开源项目评选「最佳人气项目」「最积极运营项目」 !
Event Handler 获得 2020 年度 OSC 中国开源项目评选「最积极运营项目」 !
授权协议 未知
开发语言
操作系统 未知
软件类型 开源软件
开源组织
地区 不详
投 递 者 不详
适用人群 未知
收录时间 2008-09-19

软件简介

Event Handler plugin was made to make handling your event handlers a little easier. It adds one new method called eventH to jQuery which can only be invoked using $.eventH(). It expects two arguments (action, options) which must follow the following guidelines:
action must be a string == "bind" OR "unbind" OR "rebind" OR "add" OR "remove"
options must be an object (hash) that may contain the following:

  useList: {
    key: "the value must be set, but is not used",
    anotherKey: null,
    keying: "Bla",
    hex: null
  }
  skipList: {
    key: "same rules as useList"
  }
  newHandler: {
    type: ["click", "mouseover", "mouseout"],
    name: "key",
    selector: "jQuery Selector",
    func: [
      function(){
        //Click
      },
      function(){
        //MouseOver
      },
      function(){
        //MouseOut
      }
    ]
  },
  handlers: [
    {type:["change", "click", "focus", "blur"], name: "key", selector: "p", func: [function(){
        //Change
      },
      function(){
        //Click
      },
      function(){
        //Focus
      },
      function(){
        //Blur
      }
    },
    {type:["change", "click", "focus", "blur"], name: "key", selector: "p", func: [function(){
        //Change
      },
      function(){
        //Click
      },
      function(){
        //Focus
      },
      function(){
        //Blur
      }
    },...
  ]

NOTE: handlers should be passed the first time the function is invoked and should not be passed again (if it is, it will be discarded). Use the newHandler option and the add action to add new handlers.

The idea is that you call the eventH() method inside the jQuery ready function with action == "bind" and options containing just the handlers array. The keys that you define can be used in the useList and skipList when calling "bind" OR "unbind" OR "rebind" OR "remove" ("add" doesn't use the useList or skipList).

The "rebind" action is useful when you have an element who's content keeps changing (completely) but keeps the same selectors there.
For Example:

<div class='cont'>
  <span class='name'>Name</span>
</div>

Now lets say you changed the content of the div with $(".cont").html("Name 2");. Any event handlers you had registered with the span would be lost. If you call the rebind action with the key you defined for that span, you can recover all event handlers. (NOTE: This is only common in ajax applications where the server is returning HTML).

The "unbind" action is useful if you want to temporarily remove all event handlers from an element (or set of elements). It is also internally used for the "rebind" action.

The "bind" action can be called if/when you want to recover the event handlers you unbound with the "unbind" action.

The "add" action is useful if you want to add an element to the list for lator use with "unbind"/"rebind"/"bind". Or if you want to add multiple event handlers to a single group of evelent(s) (eg. mouseover, mouseout, click...) all at once. The normal jQuery way of doing this would be like this: $("selector").mouseover(...).mouseout(...).click(...);

This plugin is no where near perfect and I'm hoping to have some time to improve it.

展开阅读全文

评论 (0)

加载中
更多评论
暂无内容
暂无内容
发表了问答
2015/08/23 21:36

在DOM事件流中,什么阶段可以禁止事件的传播?capture?target?bubble?

在DOM事件流中,什么阶段可以禁止事件的传播?capture?target?bubble?

1
0
发表了问答
2015/05/04 09:19

如何向js函数中传入两个参数

我在一个js函数中想传入一个参数,但是这个参数同时又需要判断浏览器,这个函数如下: function showDetail(e) {   var e = e || window.event;   var box = document.getElementById("box_detail");   var content = currentData;   box.innerHTML=message;   box.style.display = "block"; /*  box.style.top = e.clientY - content.offsetTop + "px";   box.style.left = e.clientX - content.offsetLeft + "px";*/   box.style.top ...

4
0
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部