TR move up && TR move down
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TR move up && TR move down相关的知识,希望对你有一定的参考价值。
code display ::
<!DOCTYPE html>
<html>
<head>
<link href="bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>1,000</td>
<td>Lorem</td>
<td>ipsum</td>
<td class="shangyi">dolor</td>
<td class="xiayi">sit</td>
</tr>
<tr>
<td>1,001</td>
<td>amet</td>
<td>consectetur</td>
<td class="shangyi">adipiscing</td>
<td class="xiayi">elit</td>
</tr>
<tr>
<td>1,002</td>
<td>Integer</td>
<td>nec</td>
<td class="shangyi">odio</td>
<td class="xiayi">Praesent</td>
</tr>
<tr>
<td>1,003</td>
<td>libero</td>
<td>Sed</td>
<td class="shangyi">cursus</td>
<td class="xiayi">ante</td>
</tr>
<tr>
<td>1,004</td>
<td>dapibus</td>
<td>diam</td>
<td class="shangyi">Sed</td>
<td class="xiayi">nisi</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<script>
$(function(){
$(".shangyi").click(function(){
var $currentTr = $(this).parent();
var $prevTr = $currentTr.prev();
if($prevTr){
$currentTr.insertBefore($prevTr);
}
});
$(".xiayi").on(‘click‘,function(){
var $currentTr = $(this).parent();
var $nextTr = $currentTr.next();
if($nextTr){
$currentTr.insertAfter($nextTr);
}
});
});
</script>
</body>
</html>
以上代码展示表格行点击事件的上下移动的效果,表格用到了bootstrap的样式
以上是关于TR move up && TR move down的主要内容,如果未能解决你的问题,请参考以下文章