有没有办法用jquery赶上dom bubble?

时间:2016-02-03 12:32:53

标签: jquery oop object event-handling event-bubbling

有没有办法在没有dom连接的情况下捕获自定义事件的事件冒泡。

function b() { 
  $(this).trigger("b"); 
  return this
}

function a() { 
   this.Test = function() {
      new b()
   }; 
   return this
}

var o = new a()
$(o).on("b",function(){console.log("o")})

o.Test() // no bubbling

2 个答案:

答案 0 :(得分:0)

您需要使用Event()对象来创建新事件:

var ev = new Event("look", {"bubbles":true, "cancelable":false});
document.dispatchEvent(ev); // the event bubbles and can't be cancelled

Src @ MDN

答案 1 :(得分:0)

这是我的解决方案,虽然我确信有更好的方法(因为我使用了不在文档上的Dom元素)

import datetime 
df.loc[datetime.date(year=2014,month=1,day=1):datetime.date(year=2014,month=2,day=1)]