Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/05/2011, 17:16
oms02
 
Fecha de Ingreso: junio-2010
Mensajes: 373
Antigüedad: 13 años, 10 meses
Puntos: 11
primer plugin

Hola a todos. Estoy en la creacion de mi primer plugin y como imaginareis, me hago lios...

El codigo en si es muy sencillo, pero no se pq no funciona. creo que es debido a los problemillas de conceptos...

me echais un cable??

Código Javascript:
Ver original
  1. $.fn.validaRegistro = function (mensaje) {
  2.     $(this).each(function() {
  3.         var pos = $(this).position();
  4.         var veloc2 = 1000;
  5.         var nombre = $("#nombre");
  6.         var veloc = 600;
  7.         var c_valido = "silver";
  8.         var c_error = "#FF8B8F";
  9.        
  10.         function error(mensaje){
  11.             $(this).css({border:'2px solid red'});
  12.             $(this).animate({backgroundColor: c_error},veloc);
  13.             var div = "<div class='tooltip-registro'>" + mensaje + "</div>";
  14.             $(this).after(div);
  15.            
  16.             var posLeft = pos.left + $(this).width();
  17.             var posTop = pos.top;
  18.             $(this).next().css({"top": posTop + "px","left": posLeft + "px","position": "absolute"});
  19.         }
  20.        
  21.         function valido(){
  22.             $(this).css({border:'2px solid #000'});
  23.             $(this).animate({backgroundColor: c_valido},veloc);
  24.             $(this).next().fadeOut(veloc2);
  25.         }
  26.        
  27.         function validaNombre(){
  28.             if(nombre.val().length < 4 || nombre.val().length > 15)
  29.                 {error(mensaje);}
  30.             else if(!$(this).val().match(/^[0-9a-zA-Z]+$/))
  31.                 {error(mensaje);}
  32.             else
  33.                 {valido();}
  34.         }
  35.  
  36. $(this).focusin(function(){$(this).next().fadeOut(veloc2);});
  37. $(this).blur(validaNombre);
  38.        
  39. });
  40. }

Código HTML:
Ver original
  1. $(document).ready(function(){
  2. <script language="javascript" type="text/javascript">
  3. $("#nombre").validaRegistro("El nombre solo puede contener letras y numeros. Debe tener entre 4 y 15 caracteres");
  4. });

Gracias!