基本表格结构如下
<table border="1">
<thead>
<tr>
<th></th>
<th>操作</th>
<th>项目阶段</th>
</tr>
</thead>
<tbody id="items">
<tr>
<td class="xh">1</td>
<td><a class="btn btn-danger">你好</a></td>
<td>
<button onclick="up(this)">上移</button><button onclick="down(this)">下移</button>
</td>
</tr>
<tr>
<td class="xh">2</td>
<td><a class="btn btn-danger">再见</a></td>
<td>
<button onclick="up(this)">上移</button><button onclick="down(this)">下移</button>
</td>
</tr>
<tr>
<td class="xh">3</td>
<td><a class="btn btn-danger">再也不见</a></td>
<td>
<button onclick="up(this)">上移</button><button onclick="down(this)">下移</button>
</td>
</tr>
</tbody>
</table>
行向上移动的js代码
window.up = function(obj) {
var objParentTR=j$(obj).parent().parent();
var prevTR=objParentTR.prev();
if(prevTR.length>0) {
prevTR.insertAfter(objParentTR);
}
else{
alert('已经是第一行啦');
}
}
行向下移动的js代码
window.down = function(obj) {
var objParentTR=j$(obj).parent().parent();
var nextTR=objParentTR.next();
if(nextTR.length>0) {
nextTR.insertBefore(objParentTR);
}
else{
alert('已经是最后一行啦');
}
}