Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. 新的DOM2 用法可以addEventListener()這個函數來觀察到:
  2.  
  3. addEventListener(event,function,capture/bubble);
  4. 參數event如上表所示, function是要執行的函數, capture與bubble分別是W3C制定得兩種時間模式,簡單來說capture就是從document的開始讀到最後一行,
  5. 再執行事件, 而bubble則是先尋找指定的位置再執行事件.capture/bubble的參數是布林值, True表示用capture, False則是bubble.Windows Internet Explorer
  6. 也有制定一種EventHandler, 是 attachEvent(), 格式如下:
  7.  
  8. window.attachEvent("submit",myFunction());
  9. 比較特別的是attachEvent不需要指定capture/bubble的參數, 因為在windows IE環境下都是使用Bubble的模式.
  10.  
  11. W3C 及 IE 同時支援移除指定的事件, 用途是移除設定的事件, 格式分別如下:
  12.  
  13. W3C格式:
  14.  
  15. removeEventListener(event,function,capture/bubble);
  16. Windows IE的格式如下:
  17.  
  18. detachEvent(event,function);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement