2009-08-31 5 views
-2
<table id="experiences" cellpadding="0" border="1" width="100%" height="100%"> 

<tr><th>Company</th><th>Job Title</th><th>Industry</th><th>Job Function</th><th>Start Date</th><th>End Date</th></tr> 
<tr> 
    <td><input type="text" name="company1" class="w100" /></td><td><input type="text" name="jobTitle1" class="w100" value="" /></td><td><input type="text" name="industry1" class="w100" value="" /></td><td><input type="text" name="jobFunction1" class="w100" /></td><td><input type="text" name="startDateJob1" class="w100" /></td><td><input type="text" name="endDateJob1" class="w100" /></td> 
</tr> 
<tr> 
    <td><input type="text" name="company2" class="w100" /></td><td><input type="text" name="jobTitle2" class="w100" /></td><td><input type="text" name="industry2" class="w100" /></td><td><input type="text" name="jobFunction2" class="w100" /></td><td><input type="text" name="startDateJob2" class="w100" /></td><td><input type="text" name="endDateJob2" class="w100" /></td> 
</tr> 
<tr> 
    <td><input type="text" name="company3" class="w100" /></td><td><input type="text" name="jobTitle3" class="w100" /></td><td><input type="text" name="industry3" class="w100" /></td><td><input type="text" name="jobFunction3" class="w100" /></td><td><input type="text" name="startDateJob3" class="w100" /></td><td><input type="text" name="endDateJob3" class="w100" /></td> 
</tr> 
<tr> 
    <td><input type="text" name="company4" class="w100" /></td><td><input type="text" name="jobTitle4" class="w100" /></td><td><input type="text" name="industry4" class="w100" /></td><td><input type="text" name="jobFunction4" class="w100" /></td><td><input type="text" name="startDateJob4" class="w100" /></td><td><input type="text" name="endDateJob4" class="w100" /></td> 
</tr> 

</table> 

Voici l'autre table:Comment obtenir des paires {id: value} et copier dans une autre table avec la même structure efficacement à partir du tableau ci-dessous avec jQuery?

<table id="experiences-mirror" cellpadding="0" border="1" width="100%" height="100%"> 
    <tr><th>Company</th><th>Job Title</th><th>Industry</th><th>Job Function</th><th>Start Date</th><th>End Date</th></tr> 
    <tr> 
     <td></td><td></td><td></td><td></td><td></td><td></td> 
    </tr> 
    <tr> 
     <td></td><td></td><td></td><td></td><td></td><td></td> 
    </tr> 
    <tr> 
     <td></td><td></td><td></td><td></td><td></td><td></td> 
    </tr> 
    <tr> 
     <td></td><td></td><td></td><td></td><td></td><td></td> 
    </tr> 
</table> 
+0

-il judicieux de réduire les échantillons. – Dmitriy

Répondre

1
var obj = {}; 
$('#experiences input').each(function() { 
    obj[$(this).attr('name')] = $(this).val(); 
}); 

En ce qui concerne la copie des valeurs cela devrait fonctionner.

// clone original table 
var tab = $('#experiences').clone(); 

// change the id 
tab.attr('id', 'experiences-mirror'); 

// replace inputs with corresponding values 
tab.find('input').each(function() { 
    var elem = $(this); 
    elem.remove(); 
    elem.parent().text(elem.val()); 
}); 

// replace empty tab with filled one 
$('#experiences-mirror').replaceWith(tab); 
+0

@ RaYell, j'ai changé ma question.Désolé pour le retard. – omg

+0

Vérifiez ma réponse mise à jour. – RaYell

+0

@ RaYell, comment faire pour appliquer également lorsque certains sont changés en dans sa cellule, tandis que la seconde contient du texte en clair.Alors votre code ne fonctionnera pas, non? – omg

+0

alors votre question est fausse que vous avez dit la même structure, à droite :) – redsquare

+0

c'mon, comment est-il difficile de trouver les entrées, obtenir la valeur dans la cellule, puis retirez l'entrée .... – redsquare

Questions connexes