Ver Mensaje Individual
  #6 (permalink)  
Antiguo 17/12/2010, 11:06
Dany_s
 
Fecha de Ingreso: diciembre-2009
Ubicación: Misiones
Mensajes: 867
Antigüedad: 14 años, 5 meses
Puntos: 65
Respuesta: Jquery trabajar con inputs dentro de td

que no sirven los id dinámicos!!! jeje deberias practicar un poco con estos métodos http://api.jquery.com/category/traversing/ y ver que hacen

si tenes un boton para borrar en cada fila entonce cuando hacen click subis hasta ese tr y lo borras

Código HTML:
Ver original
  1.     <head>
  2.         <title>Ejemplo</title>
  3.         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  4.     </head>
  5.         <script type="text/javascript">
  6.             $( function (){
  7.                 $('#agregar').click( function(){
  8.                     newTr = $('tr:first').clone();
  9.                     $('input, select', newTr).val('');
  10.                     $('#laTabla').append(newTr);
  11.                     return false;
  12.                 });
  13.  
  14.                 $('.eliminar').live('click', function(){
  15.                     $(this).closest('tr').remove();
  16.                 });
  17.  
  18.             });
  19.         </script>
  20.     <body>
  21.  
  22.     <div>
  23.         <table id="laTabla">
  24.             <tr>
  25.                 <td><span class="item">Name</span></td>
  26.                 <td><input  type="text"  name="nombre[]" /></td>
  27.                 <td><input  type="text"  name="uno[]" /></td>
  28.                 <td><input  type="text"  name="dos[]" /></td>
  29.                 <td><select name="tres"><option>1</option><option>2</option</select></td>
  30.                 <td><select name="cuatro"><option>1</option><option>2</option</select></td>
  31.                 <td><select name="cinco"><option>1</option><option>2</option</select></td>
  32.                 <td><button class="eliminar">Eliminar</button></td>
  33.             </tr>
  34.         </table>
  35.         <input id="agregar" type="button" value="+" />
  36.     </div>
  37.  
  38.     </body>
  39. </html>

y esto
$('select', newTr).eq(0).val('');
$('select', newTr).eq(1).val('');
$('select', newTr).eq(2).val('');

es lo mismo que esto
$('select', newTr).val('');


y todo junto
$('input', newTr).eq(0).val('');
$('input', newTr).eq(1).val('');

$('select', newTr).eq(0).val('');
$('select', newTr).eq(1).val('');
$('select', newTr).eq(2).val('');


es lo mismo esto
$('select, input', newTr).val('');