var oDiv = document.getElementById("myDiv") , event;
oDiv.addEventListener("myevent",function (e) {
console.log(e.detail);
});
if(document.implementation.hasFeature("CustomEvents" , "3.0")){
event = document.createEvent("CustomEvent");
// 事件類型,是否冒泡,是否阻止瀏覽器的默認行爲
event.initCustomEvent("myevent" , true , false , {a:1,b:2});
console.log(event);
// 觸發myevent事件
oDiv.dispatchEvent(event);
}複製代碼