jquery插入一个新行

时间:2010-02-24 19:45:41

标签: 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>

1 个答案:

答案 0 :(得分:3)

像这样:

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