入力時に背景色を変える。

4月 18, 2007 · Posted in javascript 

概要

テキストエリアにフォーカスされたときに背景色を変更する

Java Script
function setInputFocus(){
var inputFocus = function(elm){
elm.style.backgroundColor="#eeffee";
}
var inputBlur= function(elm){
elm.style.backgroundColor="#ffffff";
}
 
if (!document.getElementsByTagName){ return; }

var anchors = document.getElementsByTagName('input');
for (var i=0; i<anchors.length; i++){
 
var anchor = anchors[i];
 
var idAttribute = String(anchor.getAttribute('type'));
if ( idAttribute.toLowerCase().match('text') ){
anchor.onfocus = function () { inputFocus(this);}
anchor.onblur = function () { inputBlur(this);}
}
}
}
Event.observe(window, 'load', setInputFocus, false);

Comments

Comments are closed.