Foros del Web » Programando para Internet » Jquery »

Como ejecutar funciones como jquery

Estas en el tema de Como ejecutar funciones como jquery en el foro de Jquery en Foros del Web. Hola, Quisiera saber como hacer como jQuey que activa sus funcuiones como: $('#id').mifuncion(); Gracias Salu2...
  #1 (permalink)  
Antiguo 04/04/2009, 18:21
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Como ejecutar funciones como jquery

Hola,
Quisiera saber como hacer como jQuey que activa sus funcuiones como:
$('#id').mifuncion();
Gracias
Salu2
__________________
Half Music - www.halfmusic.com

Última edición por pato12; 05/04/2009 a las 08:39
  #2 (permalink)  
Antiguo 04/04/2009, 18:27
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Como hacer esto

No entendí exactamente lo que quieres, ¿lo de $? ¿mifuncion()?
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 04/04/2009, 18:31
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Respuesta: Como hacer esto

Hola,
Viste la funcion queme ayudaste a crear hace rato ($css). Queiro en ves de usarla:
$css('id_div',{color:'#ffffff'});
sea
$('id_div').$css({color:'#ffffff'}); como en jQuery.
Gracias
Salu2
__________________
Half Music - www.halfmusic.com
  #4 (permalink)  
Antiguo 04/04/2009, 20:28
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 11 meses
Puntos: 834
Respuesta: Como hacer esto

Creo que te referís al encadenamiento (chaining). Se logra extendiendo los objetos para agregarle funcionalidad y haciendo que cada una de estas extensiones retorne el mismo objeto. Un ejemplo reducido:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title></title>
<
script>
var 
fw=(function(){
    var 
metodosPrivados={
        
css:function(prop,valor){
            if(!
valor)
                return 
this.style[prop];
            else
                 
this.style[prop]=valor;
            return 
this;
        },
        
addEvent: function(typefn ) {
            if ( 
this.addEventListener ) {
                
this.addEventListenertypefnfalse );
            } else if(
this.attachEvent){
                var 
_this=this;
                var 
f= function(){fn.call(_this,window.event);}
                
this.attachEvent'on'+typef);
                
this[fn.toString()+type]=f;
            }else{
                
this['on'+type]=fn;
            }
            return 
this;
        }
    }
    return {
        
extend:function(molde,obj){
            for(var 
i in molde)
                
obj[i]=molde[i];
            return 
obj;
        },
        
get:function(id){
            return 
fw.extend(metodosPrivados,document.getElementById(id))
        }
    }
})();
var $=
fw.get;
onload=function(){
    $(
'p').css('backgroundColor','orange').css('width','500px').addEvent('click',function(){this.css('backgroundColor','red');});
}
</script>
</head>

<body>
<div id="p" style="background-color:#F00">test</div>
</body>
</html> 
Notar el return this en cada funcionalidad agregada.
pato12, un favor: usá títulos más descriptivos así le sirven a alguien que use el buscador del foro.

Última edición por Panino5001; 04/04/2009 a las 20:48
  #5 (permalink)  
Antiguo 05/04/2009, 08:38
Avatar de pato12  
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 16 años, 7 meses
Puntos: 101
Respuesta: Como hacer esto

Hola,
Muchas gracias!.
Ya le cambio el titulo.
Salu2
__________________
Half Music - www.halfmusic.com
  #6 (permalink)  
Antiguo 05/04/2009, 08:49
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 11 meses
Puntos: 834
Respuesta: Como ejecutar funciones como jquery

Gracias por cambiar el título! Por las dudas, aclaro que hay otras formas de hacer lo mismo. Ejemplo:

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title></title>
<
script>
function 
css(p,v){
    if(!
v)
        return 
this.style[p]
    
this.style[p]=v;
    return 
this;
}

function $(
x){
    
document.getElementById(x).css=function(){
            return 
css.apply(document.getElementById(x),[].slice.call(arguments));
    }
    return 
document.getElementById(x);
}
onload=function(){
    $(
'p').css('backgroundColor','orange').css('width','500px');
}
</script>
</head>

<body>
<div id="p" style="background-color:#F00">test</div>

</body>
</html> 
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:00.