Jquery打造可以上下移动行的表格
html] view plaincopyprint?
- <html>
- <head>
- <title>表格</title>
- <styletype="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>
- <scriptsrc="jquery-1.3.2.js"type="text/javascript">
- </script>
- <scripttype="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>
- <tableclass="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><inputtype="text"name="textfield"class="editText"id="textfield"></td>
- <td></td>
- <td><inputtype="text"name="textfield5"id="textfield5"></td>
- <td><inputtype="checkbox"name="checkbox"id="checkbox"></td>
- <td><inputtype="checkbox"name="checkbox5"id="checkbox5"></td>
- <td><ahref="javascript:void(0)"onClick="moveUp(this)">上移</a><ahref="javascript:void(0)"onClick="moveDown(this)">下移</a></td>
- </tr>
- <tr>
- <td>2</td>
- <td><inputtype="text"name="textfield2"id="textfield2"></td>
- <td></td>
- <td><inputtype="text"name="textfield6"id="textfield6"></td>
- <td><inputtype="checkbox"name="checkbox2"id="checkbox2"></td>
- <td><inputtype="checkbox"name="checkbox6"id="checkbox6"></td>
- <td><ahref="javascript:void(0)"onClick="moveUp(this)">上移</a><ahref="javascript:void(0)"onClick="moveDown(this)">下移</a></td>
- </tr>
- <tr>
- <td>3</td>
- <td><inputtype="text"name="textfield3"id="textfield3"></td>
- <td></td>
- <td><inputtype="text"name="textfield7"id="textfield7"></td>
- <td><inputtype="checkbox"name="checkbox3"id="checkbox3"></td>
- <td><inputtype="checkbox"name="checkbox7"id="checkbox7"></td>
- <td><ahref="javascript:void(0)"onClick="moveUp(this)">上移</a><ahref="javascript:void(0)"onClick="moveDown(this)">下移</a></td>
- </tr>
- <tr>
- <td>4</td>
- <td><inputtype="text"name="textfield4"id="textfield4"></td>
- <td></td>
- <td><inputtype="text"name="textfield8"id="textfield8"></td>
- <td><inputtype="checkbox"name="checkbox4"id="checkbox4"></td>
- <td><inputtype="checkbox"name="checkbox8"id="checkbox8"></td>
- <td><ahref="javascript:void(0)"onClick="moveUp(this)">上移</a><ahref="javascript:void(0)"onClick="moveDown(this)">下移</a></td>
- </tr>
- </table>
- </body>
- </html>