[转载]Jquery打造可以上下移动行的表格 – Joe Zhou – 博客园.
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>表格</title> <style type="text/css"> .editText { border-width:1px; border-top-style:none; border-left-style:none; border-right-style:none; border-bottom-style:solid; border-color:#030; width:100%; } </style> <script src="jquery.js" type="text/javascript"> </script> <script type="text/javascript"> function moveUp(obj) { var current=$(obj).parent().parent(); var prev=current.prev(); if(current.index()>1) { current.insertBefore(prev); } } function moveDown(obj) { var current=$(obj).parent().parent(); var next=current.next(); if(next) { current.insertAfter(next); } } </script> </head> <body> <table class="grid" width="100%" border="1" cellspacing="0" cellpadding="0"> <tr> <td>字段英文名</td> <td>字段中文名</td> <td>字段数据类型</td> <td>列宽</td> <td>是否显示</td> <td>是否作为查询条件</td> <td>调整顺序</td> </tr> <tr> <td>1</td> <td><input type="text" name="textfield" class="editText" id="textfield"></td> <td> </td> <td><input type="text" name="textfield5" id="textfield5"></td> <td><input type="checkbox" name="checkbox" id="checkbox"></td> <td><input type="checkbox" name="checkbox5" id="checkbox5"></td> <td><a href="javascript:void(0)" onClick="moveUp(this)">上移</a><a href="javascript:void(0)" onClick="moveDown(this)">下移</a></td> </tr> <tr> <td>2</td> <td><input type="text" name="textfield2" id="textfield2"></td> <td> </td> <td><input type="text" name="textfield6" id="textfield6"></td> <td><input type="checkbox" name="checkbox2" id="checkbox2"></td> <td><input type="checkbox" name="checkbox6" id="checkbox6"></td> <td><a href="javascript:void(0)" onClick="moveUp(this)">上移</a><a href="javascript:void(0)" onClick="moveDown(this)">下移</a></td> </tr> <tr> <td>3</td> <td><input type="text" name="textfield3" id="textfield3"></td> <td> </td> <td><input type="text" name="textfield7" id="textfield7"></td> <td><input type="checkbox" name="checkbox3" id="checkbox3"></td> <td><input type="checkbox" name="checkbox7" id="checkbox7"></td> <td><a href="javascript:void(0)" onClick="moveUp(this)">上移</a><a href="javascript:void(0)" onClick="moveDown(this)">下移</a></td> </tr> <tr> <td>4</td> <td><input type="text" name="textfield4" id="textfield4"></td> <td> </td> <td><input type="text" name="textfield8" id="textfield8"></td> <td><input type="checkbox" name="checkbox4" id="checkbox4"></td> <td><input type="checkbox" name="checkbox8" id="checkbox8"></td> <td><a href="javascript:void(0)" onClick="moveUp(this)">上移</a><a href="javascript:void(0)" onClick="moveDown(this)">下移</a></td> </tr> </table> </body> </html>