フォーカスされたテキストボックスの背景色を変更する

先日の、フォーカスされたテキストボックスの背景色を変更する - 偏った言語信者の垂れ流しprototype.jsでイベントを登録するようにした。

Event.observe(window, 'load', function(){
  function input_focused() {
    this.style.backgroundColor="#DFF";
  }

  function input_blured() {
    this.style.backgroundColor="";
  }

  $A(document.forms[0].elements).each(function(obj, index){
    if (obj.type == "text") {
      Event.observe(obj, 'focus', input_focused, false);
      Event.observe(obj, 'blur', input_blured, false);
    }
  });
}, false);
  • 追記

forループのところをeachに変えてみた。