这个问题已经在这里有了答案:




已关闭8年。






我想在更改事件上向表中添加新行。这是我到目前为止的内容:

$('#CourseID').change(function() {
    $('#CourseListTable > tr > td:last').append('<td>...</td>');
});

这是我的桌子:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<table id="CourseListTable">
    <tr>
        <th>Course ID</th>
        <th>Course Section</th>
        <th>Level</th>
    </tr>
    <tr>
        <td><select name="CourseID" id="CourseID"></select></td>
        <td><select name="CourseSection" id="CourseSection"></select></td>
        <td><select name="Level" id="Level"></select></td>
    </tr>
</table>

我无法使它正常工作。我在这里错过了什么,有人可以让我知道我的错误所在吗?

提前致谢。

最佳答案

您提到了附加行,但是在代码中仅附加了单元格。

如果您实际上需要附加整行,请尝试以下操作:

$('#CourseID').change(function() {
    $('<tr/>').append('<td>...</td>').insertAfter('#CourseListTable tr:last');
});

09-25 17:43
查看更多