Reputation: 636
Im doing my first plugin in jquery for practising and It won't work, i have seen tutorials and the api documentation and didnt find the problem.
I have a select in html and a span.sl1. and I call it this way:
$("select").selectFunc("onChange");
My plugin code is:
(function( $ ){
var metodos = {
init : function(opciones) {
var configuracion = {
container:$('span.sl1'),
valor:$(this).val()
};
return this.each(function(){
if(opciones){
configuracion = $.extend(configuracion,opciones);
}
});
},
onChange:function(opciones){
return this.each(function(){
$(this).bind('change',function(){
container.html(valor);
});
});
},
unbind : function (){
return this.each(function(){
$(this).unbind('mouseover');
$(this).unbind('mouseout');
});
}
};
$.fn.selectFunc = function( metodos ) {
if (metodos[method] ) {
return metodos[ metodo ].apply( this, Array.prototype.slice.call( argumentos, 1 ));
}
else if ( typeof metodo === 'object' || ! metodo ) {
return metodos.init.apply( this, argumentos );
}
else {
$.error( 'Este método ' + metodo + ' no existe en jQuery.estiloPropio' );
}
};
})( jQuery );
Upvotes: 1
Views: 389