jquery实现手动排序insertAfter和insertBefore用法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>insertAfter和insertBefore用法</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('.up_btn').click(function(){
$(this).closest('tr').insertBefore($(this).closest('tr').prev());
})
$('.down_btn').click(function(){
$(this).closest('tr').insertAfter($(this).closest('tr').next());
})
})
</script>
</head>

<body>
<table width="600" border="1">
<tr>
<td>序号</td>
<td>标题</td>
<td>排序</td>
</tr>
<tbody>
<tr bgcolor="#0066CC">
<td>1</td>
  <td>1</td>
<td>
<input type="button" value="上移" class="up_btn" />
<input type="button" value="下移" class="down_btn" />
</td>
</tr>
<tr bgcolor="#006666">
<td>2</td>
  <td>2</td>
<td>
<input type="button" value="上移" class="up_btn" />
<input type="button" value="下移" class="down_btn" />
</td>
</tr>
<tr bgcolor="#993333">
<td>3</td>
  <td>3</td>
<td>
<input type="button" value="上移" class="up_btn" />
<input type="button" value="下移" class="down_btn" />
</td>
</tr>
<tr bgcolor="#CC6600">
<td>4</td>
  <td>4</td>
<td>
<input type="button" value="上移" class="up_btn" />
<input type="button" value="下移" class="down_btn" />
</td>
</tr>
<tr bgcolor="#999999">
<td>5</td>
  <td>5</td>
<td>
<input type="button" value="上移" class="up_btn" />
<input type="button" value="下移" class="down_btn" />
</td>
</tr>
</tbody>
</table>

</body>
</html>

你可能感兴趣的:(jquery)