Foros del Web » Programando para Internet » Javascript »

Cambiar boton por imagen...

Estas en el tema de Cambiar boton por imagen... en el foro de Javascript en Foros del Web. Hola... No soy muy experto en JavaScript y es por eso que os pido vuestra ayuda... Tengo un .JS que sirve para subir multiples archivos ...
  #1 (permalink)  
Antiguo 13/04/2012, 17:28
Avatar de andrewp  
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 1.160
Antigüedad: 20 años, 8 meses
Puntos: 5
Pregunta Cambiar boton por imagen...

Hola...

No soy muy experto en JavaScript y es por eso que os pido vuestra ayuda...

Tengo un .JS que sirve para subir multiples archivos a un servidor, acompañado de un formulario típico en PHP.
El caso, es que el código de JS me muestra un botón para eliminar el archivo de la lista (delete) pero es muy grande y me gustaría cambiarlo por una imagen más agradable (línea 33 y 34). El código es el siguiente:

Código Javascript:
Ver original
  1. function MultiSelector( list_target, max ){
  2.     this.list_target = list_target;
  3.     this.count = 0;
  4.     this.id = 0;
  5.     if( max ){this.max = max;
  6.     } else {
  7.         this.max = -1;};
  8.     this.addElement = function( element ){
  9.         if( element.tagName == 'INPUT' && element.type == 'file' ){
  10.             element.name = 'file_' + this.id++;
  11.             element.multi_selector = this;
  12.             element.onchange = function(){
  13.                 var new_element = document.createElement( 'input' );
  14.                 new_element.type = 'file';
  15.                 this.parentNode.insertBefore( new_element, this );
  16.                 this.multi_selector.addElement( new_element );
  17.                 this.multi_selector.addListRow( this );
  18.                 this.style.position = 'absolute';
  19.                 this.style.left = '-5000px';
  20.             };
  21.             if( this.max != -1 && this.count >= this.max ){
  22.                 element.disabled = true;
  23.             };
  24.             this.count++;
  25.             this.current_element = element;
  26.         } else {
  27.             alert( 'Error: not a file input element' );
  28.         };
  29.     };
  30.     this.addListRow = function( element ){
  31.         var new_row = document.createElement( 'div' );
  32.         var new_row_button = document.createElement( 'input' );
  33.         new_row_button.type = 'button';
  34.         new_row_button.value = 'Delete';
  35.         new_row.element = element;
  36.         new_row_button.onclick= function(){
  37.             this.parentNode.element.parentNode.removeChild( this.parentNode.element );
  38.             this.parentNode.parentNode.removeChild( this.parentNode );
  39.             this.parentNode.element.multi_selector.count--;
  40.             this.parentNode.element.multi_selector.current_element.disabled = false;return false;
  41.         };
  42.         new_row.innerHTML = element.value;
  43.         new_row.appendChild( new_row_button );
  44.         this.list_target.appendChild( new_row );
  45.     };
  46. };

En cualquier caso, las líneas son:

Código Javascript:
Ver original
  1. new_row_button.type = 'button';
  2. new_row_button.value = 'Delete';

Sabéis cómo puedo hacerlo?

Gracias!
__________________
Andrew :P
  #2 (permalink)  
Antiguo 13/04/2012, 21:15
Avatar de emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Cambiar boton por imagen...

Bastaría que le apliques una clase al input y que la definas en tu css

Código Javascript:
Ver original
  1. new_row_button.className = 'btn';

Código CSS:
Ver original
  1. <style type="text/css">
  2. /*<![CDATA[*/
  3.  
  4. /* estilos */
  5. .btn{
  6. background-color: yellow;
  7. width: 100px;
  8. height: 30px;
  9. }
  10. /*]]>*/
  11. </style>

Podés quitarle el borde, darle un background transparente con una imagen de fondo, etc

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.

Última edición por emprear; 13/04/2012 a las 21:20
  #3 (permalink)  
Antiguo 14/04/2012, 16:55
Avatar de andrewp  
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 1.160
Antigüedad: 20 años, 8 meses
Puntos: 5
Respuesta: Cambiar boton por imagen...

Hola emprear... Muchas gracias, tu post me resultado de gran ayuda.

Para compartir la solución, solo debo añadir que en el código CSS, en vez de añadir un color, he añadido el path a mi imagen:

Código CSS:
Ver original
  1. <style type="text/css">
  2. .btn {
  3.   background-image: url('/path/botonborrar.jpg');
  4.   width: 20px;
  5.   height: 20px;
  6.   border: none;
  7. }
  8. </style>

Gracias!!!!!

POST RESUELTO
__________________
Andrew :P
  #4 (permalink)  
Antiguo 14/04/2012, 17:05
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Respuesta: Cambiar boton por imagen...

Hola:

Por cierto, no debes entrecomillar la url de tu imagen... me refiero al estilo background-image (y me alegro que hayas resuelto el tema).

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo

Etiquetas: formulario, html, input, js, php, botones
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 10:23.