JQuery实现表格行的上移、下移、删除、增加
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="/Test/js/jquery.min.js"></script>
<script type="text/javascript">
//删除
function del(t){
$(t).parent().parent().remove();
} //上移
function up(t){
var i=$(t).parent().parent().index();//当前行的id
if(i>1){//不是表头,也不是第一行,则可以上移
var tem0=$(t).parent().parent().html();
var tem1=$(t).parent().parent().prev().html();
$(t).parent().parent().prev().html(tem0);
$(t).parent().parent().html(tem1);
}
}
//下移
function down(t){
var l=$("#MyTB tr").length;//总行数
var i=$(t).parent().parent().index();//当前行的id
if(i<l-1){//不是最后一行,则可以下移
var tem0=$(t).parent().parent().html();
var tem1=$(t).parent().parent().next().html();
$(t).parent().parent().next().html(tem0);
$(t).parent().parent().html(tem1);
}
}
function add(t){
var tem0=$(t).parent().parent().html();
$(t).parent().parent().append("<tr>"+tem0+"</tr>");
}
</script>
</head>
<body>
<table id="MyTB">
<tr>
<td>xxxxxxxx</td>
<td>xxxxxxxx</td>
<td>xxxxxxxx</td>
<td>xxxxxxxx</td>
<td>
</td>
</tr>
<tr>
<td>11111111</td>
<td>11111111</td>
<td>11111111</td>
<td>11111111</td>
<td>
<input type="button" value="上" onclick="up(this)" />
<input type="button" value="下" onclick="down(this)" />
<input type="button" value="删" onclick="del(this)" />
<input type="button" value="加" onclick="add(this)" />
</td>
</tr>
<tr>
<td>22222222</td>
<td>22222222</td>
<td>22222222</td>
<td>22222222</td>
<td>
<input type="button" value="上" onclick="up(this)" />
<input type="button" value="下" onclick="down(this)" />
<input type="button" value="删" onclick="del(this)" />
<input type="button" value="加" onclick="add(this)" />
</td>
</tr>
<tr>
<td>33333333</td>
<td>33333333</td>
<td>33333333</td>
<td>33333333</td>
<td>
<input type="button" value="上" onclick="up(this)" />
<input type="button" value="下" onclick="down(this)" />
<input type="button" value="删" onclick="del(this)" />
<input type="button" value="加" onclick="add(this)" />
</td>
</tr>
<tr>
<td>44444444</td>
<td>44444444</td>
<td>44444444</td>
<td>44444444</td>
<td>
<input type="button" value="上" onclick="up(this)" />
<input type="button" value="下" onclick="down(this)" />
<input type="button" value="删" onclick="del(this)" />
<input type="button" value="加" onclick="add(this)" />
</td>
</tr>
<tr>
<td>55555555</td>
<td>55555555</td>
<td>55555555</td>
<td>55555555</td>
<td>
<input type="button" value="上" onclick="up(this)" />
<input type="button" value="下" onclick="down(this)" />
<input type="button" value="删" onclick="del(this)" />
<input type="button" value="加" onclick="add(this)" />
</td>
</tr>
</table>
</body>
</html>
JQuery实现表格行的上移、下移、删除、增加的更多相关文章
- jquery为表格行添加上下移动画效果
为项目列表项添加上下移动动画.首先想使用jquery animate来做到这一点.但我用的是table和tr作为列表和列表项,但jquery动画方法不支持table里的tr(Animations ar ...
- jQuery实现表格行上移下移和置顶
jQuery实现表格行上移下移和置顶 我们在操作列表数据的时候,需要将数据行排列顺序进行调整,如上移和下移行,将行数据置顶等,这些操作都可以在前端通过点击按钮来完成,并且伴随着简单的动态效果,轻松实现 ...
- jQuery实现表格行的动态增加与删除(改进版)
之前写过一个简单的利用jQuery实现表格行的动态增加与删除的例子,有些人评论说"如果表格中是input元素,那么删除后的东西都将自动替换,这样应该是有问题的,建议楼主改进!",故 ...
- jquery更改表格行顺序实例
使用jquery写的更改表格行顺序的小功能 表格部分: 复制代码代码如下: <table class="table" id="test_table"> ...
- jquery 行交换 上移 下移
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jQuery实现表格行的动态增加与删除
删除之前删除2行后: 1<script> 8 $(document).ready(function(){ 9 //<tr/>居中 10 $("#tab tr" ...
- jQuery实现表格行的动态增加与删除 序号 从 1开始排列
<table id="tab" border="1" width="60%" align="center" sty ...
- jquery实现表格行的动态增加和删除
$("#Addmaterial").click(function () {//Addmaterial是增加按钮的ID $("#tab tr").attr(&qu ...
- 使用jquery扩展表格行合并方法探究
1.前言 最近项目中用到一个表格中对于相同内容的数据进行行合并的需求,本来想从网上找个现成的,省的自己再造轮子.于是就开始谷歌了...不过在搜索的过程中,发现找到的工具类很多都有一个前提,就是该表格中 ...
随机推荐
- 关于hibernate中的 lazy="false“
如上图所示,warehousePicked 中包含了warehousePicking 同时,数据库中warehousePicking存在数据 ,但是在debug 时warehousePicked的be ...
- zoj 2201 No Brainer
No Brainer Time Limit: 2 Seconds Memory Limit: 65536 KB Zombies love to eat brains. Yum. Input ...
- Flask--修改默认的static文件夹的方法
修改的flask默认的static文件夹只需要在创建Flask实例的时候,把static_folder和static_url_path参数设置为空字符串即可. app = Flask(__name__ ...
- Oracle dataguard failover 实战
Oracle dataguard failover 实战 操作步骤 备库: SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINIS ...
- mysql获取行号的方法
1.不排序 语句: ) ) ) b,bigquestion 结果: 2.排序的 语句 ) ) ) b,bigquestion order by bigquestion.bigQuestionSequ ...
- ajax请求数据之后在已经有的数据前面打对勾的方法
今天遇到这么一个需求: 选择一部分人,在点击确定的时候添加到对应的div中,也就是添加到对应的表单下面,当再次查询的时候需要在已经选过的人的复选框前面打伤对勾.
- excludepathpatterns 无效
踩坑了,调了好久才调出来. 原因: 访问的API /XXX 已经转换为 /error 了. 把“/error” 也加入 excludepathpatterns 里面即可.
- poj2767,单向连通图判定,缩点+重新建图+新图DFS
/*该题被博客里标记为中等题,30分钟内1A,掌握了算法就简单了,单向连通图判定,单向连通图缩点 后必然唯一存在出度为0的点和入度为0的点,并且从入度为0的点出发,可以遍历所有点后到达出度为0点 (一 ...
- PAT (Advanced Level) 1032. Sharing (25)
简单题,不过数据中好像存在有环的链表...... #include<iostream> #include<cstring> #include<cmath> #inc ...
- [bzoj2595][WC2008]游览计划/[bzoj5180][Baltic2016]Cities_斯坦纳树
游览计划 bzoj-2595 wc-2008 题目大意:题目链接.题目连接. 注释:略. 想法:裸题求斯坦纳树. 斯坦纳树有两种转移方式,设$f[s][i]$表示联通状态为$s$,以$i$为根的最小代 ...