首页 > 技术文章 > jQuery事件

wulibo 2016-09-09 17:13 原文

$(function(){

  $('*').each(function(){

    var current = this;

    this.addEventListener('click',function(event){

      say('Capture for ' + current.tagName + '#' + current.id + 'target is' + event.target.id)  

    },true);

    

    this.addEventListener('click',function(event){

      say('Bubble for ' + current.tagName + '#' + current.id + 'target is' + event.target.id)  

    },false)

    function say(text){

      $('#console').append('<div>'+text+'</div>');

    }

  })

})

<body id='greatgrandpa'>

  <div id='grandpa'>

    <div id='pops'>

    <img id='vstar' src='vster.jpg'/>

    </div>

  </div>

  <div id='console'></div>

</body>

其实这个图已经可以看出一些东西了 事件在不同处理阶段通过DOM树的传播情况

=========================================================

关于事件

JQ 我自己推荐

input改变 用change()

其他的可以on  当然on绑定前 需要off解绑

-----------------------------------------------------------------------------------------

写一个有点用的动画 页面上从上向下模拟下坠动画

$('').each(function(){

  $(this).animate({

    opacity:0;

    top:$(window).height() - $(this).height() - $(this).position().top

  },'slow',function(){ $(this).hide(); })

})

 

基本也就是这样了 好像。。。so  先噶

 

推荐阅读