可能是重复问题:
jQuery中添加表格行
我想在改变事件发生时向我的表格添加新的一行。以下是我目前的代码:
$('#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>
我无法让这个工作起来。我在这里漏掉了些东西,有人能告诉我我的错误在哪里吗?
提前感谢。
thead
和tbody
部分,您只需要将新行附加到 tbody 中...另外,我刚刚意识到您正在附加单元格。您想要附加的是单元格还是整行? - MrOBrian