2013-01-09 26 views
-1

使用jQuery,如何輸出(並追加)表單中提交的值?jQuery - 將表格數據輸出到表格

例如,我輸入一個名稱,它應該是一個新的表格行,其中包含表單中的名稱。

<form> 
Name:<input type="text" /> 
<input type="submit" /> 
</form> 

<table> 
<tr> 
<th>Name</th> 
</tr> 
// Here the name should be appended...within a <tr><td></td></tr> 
</table> 

謝謝!

回答

0

這裏有一個簡單的例子:

$('form').on('submit', function (e) { 
    e.preventDefault(); 
    var newName = $('form').find('input[type="text"]').val(); 
    $('table').append('<tr><td>' + newName + '</td></tr>') 
}); 
+0

它的作品,謝謝! –

+0

有沒有一種方法可以點擊該行並且文本(名稱)會再次出現在表單中,因此我可以編輯它? 也許這樣的事? $('td',row).click(function){ $(this).replaceWith(「​​」+ newName +「」); }); –