Ver Mensaje Individual
  #47 (permalink)  
Antiguo 17/04/2009, 11:47
Avatar de Dude--
Dude--
 
Fecha de Ingreso: junio-2004
Ubicación: Sevilla - España
Mensajes: 197
Antigüedad: 20 años
Puntos: 4
Respuesta: Método y/u objeto de origen

Bueno todo esto me ha servido para aprender más sobre javascript y DOM pero creo que te haré caso, he modificado mi script y ahora es mucho más reducido además de coherente porque separa el estilo de la estructura.

Código css:
Ver original
  1. .inputemail { background: url(img/icontest.gif) no-repeat left; }
  2. .inputpassword{ background: url(img/icontest.gif) no-repeat left; }

Código javascript:
Ver original
  1. function checkevent(e)
  2. {
  3.     var objeto=e.srcElement || e.target;
  4.     var evento = e.type;
  5.                
  6.     if ( objeto.name == "email" )
  7.     {
  8.         if(evento == "focus")
  9.         { objeto.className = ""; }
  10.         if(evento == "blur" && objeto.value == "" )
  11.         { objeto.className = "inputemail"; }
  12.     }          
  13.     if ( objeto.name == "pass" )
  14.     {
  15.         if(evento == "focus")
  16.         { objeto.className = ""; }
  17.         if(evento == "blur" && objeto.value == "")
  18.         { objeto.className = "inputpassword"; }
  19.     }      
  20. }

Código html:
Ver original
  1. <form id="identificacion" action="index.php" method="post" enctype="application/x-www-form-urlencoded">
  2.     <input id="email" type="text" name="email" title="Email de usuario" value="" size="20" />
  3.     <input id="pass" type="password" name="pass" value="" size="15" />
  4.     <input type="submit" value="Iniciar" />
  5. </form>

Código javascript:
Ver original
  1. <script>
  2.     var inputemail = document.getElementById("email");
  3.     var inputpass = document.getElementById("pass");
  4.    
  5.     //Inicializa las clases de los dos inputs
  6.     inputemail.className = "inputemail";
  7.     inputpass.className = "inputpassword";
  8.  
  9.     if (inputemail.addEventListener) //W3C DOM
  10.     {
  11.         inputemail.addEventListener('focus', function(event) { checkevent(event) }, false);
  12.         inputemail.addEventListener('blur', function(event) { checkevent(event) }, false);
  13.     }
  14.     else //IE DOM
  15.     {
  16.         inputemail.attachEvent('onfocus', function(event) { checkevent(event) });
  17.         inputemail.attachEvent('onblur', function(event) { checkevent(event) });
  18.     }
  19.    
  20.     if (inputpass.addEventListener) //W3C DOM
  21.     {
  22.         inputpass.addEventListener('focus', function(event) { checkevent(event) }, false);
  23.         inputpass.addEventListener('blur', function(event) { checkevent(event) }, false);
  24.     }
  25.     else //IE DOM
  26.     {
  27.         inputpass.attachEvent('onfocus', function(event) { checkevent(event) });
  28.         inputpass.attachEvent('onblur', function(event) { checkevent(event) });
  29.     }
  30.     </script>
__________________
"El camino empieza renunciando el control y volviéndose flexibles, como una brizna de paja en un huracán."

"Desconozco tanto... es excitante comenzar a nadar en este mar de dudas..."