1. 程式人生 > >事件的繫結與this and 閉包的實用

事件的繫結與this and 閉包的實用

事件的繫結:

  事件作為元素的屬性

    <button onclick=""></button>

  事件作為元素物件的屬性

    element.event = function(){

}

  element.event = funName;

 

  this 實用:

    迴圈繫結事件,獲取繫結事件的物件時,需要使用this

    元素內部繫結事件時,傳入this,代表該元素物件自己

    

    標籤代表元素

    通過byid TagName  ... 獲取元素標籤物件

   閉包:

    迴圈繫結事件,將迴圈變數保留下來時,必須使用閉包

    用一組元素獲取另一組元素時,要使用到閉包