【发布时间】:2011-07-03 12:04:15
【问题描述】:
我按照以下说明添加新表的行: Add table row in jQuery
新行已成功添加,但没有获得其他行的功能(突出显示、可拖动……)。
桌子:
<table id="pubTab">
<thead>
<tr>
<td align="center">col1</td>
<td align="center">col2</td>
<td align="center">col3</td>
<td align="center">col4</td>
</tr>
</thead>
<tbody>
<tr id="1">
<td>+++<input type="text" size="40"/></td>
<td><input type="text" size="10"/></td>
<td><input type="text" size="50"/></td>
<td><input type="text" size="10" /></td>
</tr>
<tr id="2">
<td>+++<input type="text" size="40"/></td>
<td><input type="text" size="10"/></td>
<td><input type="text" size="50"/></td>
<td><input type="text" size="10"/></td>
</tr>
</tbody>
</table>
<input id="addPubTab" type="button" value="ADD" style="background-color:green; width: 170px"/>
jQuery 脚本:
<script type="text/javascript">
$(document).ready(function(){
$("#addPubTab").click(function(){
var id = "3";
var value = "<tr id=\""+id+"\">"+
"<td>+++<input type=\"text\" size=\"40\" name=\"collection_name\""+id+"/></td>"+
"<td><input type=\"text\" size=\"10\" name=\"service_name\""+id+"/></td>"+
"<td><input type=\"text\" size=\"50\" name=\"out_fname\""+id+"/></td>"+
"<td><input type=\"text\" size=\"10\" name=\"service_id\""+id+"/></td>"+
"</tr>";
$('#pubTab tbody').append(value);
});
});
</script>
问题问题: 它添加了新行,但我无法拖动它(向上/向下),因为我拖动另一根(没有用于拖动的光标)。
检查元素解析为:
<table id="pubTab">
<thead>_</thead>
<tbody>
<tr id=”1” style=”cursor: move; “ class>_</tr>
<tr id=”2” style=”cursor: move; “ class>_</tr>
<tr id=”3”>_</tr>
</tbody>
请注意,我使用的是 jQuery 脚本(拖动/排序):
$(function() { $("#pubTab:not(thead)").tableDnD(); });
请帮忙。
【问题讨论】:
-
我想你可能不得不销毁最初的可拖动对象,然后重新分配它,以更新新的孩子
-
就在
$('#pubTab tbody').append(value);btw :) 之后
标签: jquery html-table