2010-02-24 81 views
0

當用戶按下文本「添加」,然後我想創建一個帶有輸入標籤的新行。我想我的大部分工作。jquery插入一個新行

<!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> 

回答

3

像這樣:

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

謝謝!這讓我開始了。 – 2010-02-24 19:58:54