KISSY事件绑定与触发

    <body>
    <a >登录</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');

  

 

 

 

相关文章:

  • 2021-09-18
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-06-23
  • 2021-11-24
猜你喜欢
  • 2021-08-03
  • 2021-08-28
  • 2021-07-17
  • 2021-12-28
  • 2021-07-24
  • 2022-03-03
  • 2021-05-21
相关资源
相似解决方案