KISSY事件绑定与触发
<body>
<a id="a-target" href="#">登录</a>
</body>
KISSY.one('#a-target').on('click',function(){
console.log('event fired');
});
KISSY.one('#a-target').fire('click');
支持冒泡
KISSY.Event.on('body','click',function(){
console.log('body clicked');
});
//模拟点击body中的一个a标签,会冒泡到父级body,body也会触发一个click事件
KISSY.one('#a-target').fire('click');
触发通过传统方式添加的事件
document.getElementById('a-target').onclick = function(){
console.log('传统事件绑定');
};
document.getElementById('a-target').addEventListener('click',function(){
console.log('这个回调不会触发');
},false);
KISSY.one('#a-target').fire('click');
KISSY不支持addEventListener或者attachEvent方式绑定的事件
接口统一的自定义事件
KISSY.one('#a-target').on('customeventa',function(){
console.log('custom event firedx');
});
KISSY.one('#a-target').fire('customeventa');