prototype.jsを使ったイベントハンドラの追加方法
prototype.jsを読み込んでるとこんな感じでイベントハンドラ追加できる。
スマートで非常に好き。
Event.observe(element, name, observer, useCapture)
- element: オブジェクトかID
- name: イベント名 ('click', 'load' など)
- observer: イベントを処理する関数
- useCapture: true→表示前に処理, false→表示後に処理
よくある
<script> Event.observe(window, 'load', func, false); function func(){ ... } </script>
という感じになる。