2010-02-24 7 views
0

Lorsque l'utilisateur appuie sur le texte "Ajouter", alors je voudrais créer une nouvelle ligne avec une balise d'entrée. Je pense que la plupart d'entre elles fonctionnent.jquery Inséré une nouvelle ligne

<!DOCTYPE HTML> 
<html> 
<head> 
<script src="http://www.google.com/jsapi"></script> 
<script type="text/javascript"> 
function OnLoad() { 
    $('.insert').live('click', function() { 
     var currentRow = $(this).parents("tr:first"); 
     var newRow = currentRow.clone(true); 
     // Help need here: change the 3rd table data into an input control 
     currentRow.after(newRow); 
    }); 
} 
google.load("jquery", "1"); 
google.setOnLoadCallback(OnLoad); 
</script> 
</head> 
<body> 
<form> 
<table border="1"> 
<tr> 
<td class="insert">Add</td> 
<td class="delete">Erase</td> 
<td>Sample data goes here</td> 
</tr> 
</table> 
</form> 
</body> 
</html> 

Répondre

3

Comme ceci:

newRow.children('td:last').empty().append('<input>Whatever</input>'); 
+0

Merci! Cela m'a fait démarrer. –

Questions connexes