我想从数据库中输出一些数据到HTML表格中,并希望用户能够重新排列表格行。为了实现这一点,我使用了jQuery UI sortable:
<script>
$(function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
});
</script>
<?php
while($row = mysql_fetch_assoc($co_authors)) {
echo "<tr id='sortable'><td>{$row['author_email']}</td>
<td>{$row['coauthor_level']}</td>";
<td><button class='remove' id='remove' name='remove' email="<?php echo $row['author_email'] ?>"
paper="<?php echo $row['paper_id'] ?>">Remove</button></td>
</tr>";
}
?>
问题在于当我拖动一个表格的 tr
时,只有 td
被拖动了。最重要的是,只有第一行可以被拖动:效果并没有应用到其他行。我该如何解决这个问题?
id
属性必须是唯一的。您的代码创建了多个具有相同id
(sortable
) 的元素。请改用class
。 - Frédéric Hamidi