use*_*468 22 javascript jquery html-table
可能重复:
在jQuery中添加表行
我想在更改事件中向表中添加一个新行.这是我到目前为止:
$('#CourseID').change(function() {
$('#CourseListTable > tr > td:last').append('<td>...</td>');
});
Run Code Online (Sandbox Code Playgroud)
这是我的表:
<%@ 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>
Run Code Online (Sandbox Code Playgroud)
我无法让它发挥作用.我在这里遗失了什么可以让任何人让我知道我的错误在哪里?
提前致谢.
你提到追加Row但是在你的代码中你只是附加了单元格.
如果您需要实际附加一行,请尝试以下操作:
$('#CourseID').change(function() {
$('<tr/>').append('<td>...</td>').insertAfter('#CourseListTable tr:last');
});
Run Code Online (Sandbox Code Playgroud)
这一行:
$('#CourseListTable > tr > td:last').append('<td>...</td>');
Run Code Online (Sandbox Code Playgroud)
将TD(<td>...</td>
)附加到现有的TD(td:last
); 你想把它附加到TR,例如.
$('#CourseListTable > tr').append('<td>...</td>');
Run Code Online (Sandbox Code Playgroud)
当然,你提到想要添加一个新行,在这种情况下你根本不应该附加一个<td>
,你应该附加一个<tr>
(你应该将它附加到表中,显然).
归档时间: |
|
查看次数: |
1751 次 |
最近记录: |