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.前言 最近项目中用到一个表格中对于相同内容的数据进行行合并的需求,本来想从网上找个现成的,省的自己再造轮子.于是就开始谷歌了...不过在搜索的过程中,发现找到的工具类很多都有一个前提,就是该表格中 ...
随机推荐
- VS C++项目报错warning C4199: ……use /Zc:twoPhase-
具体的报错如下: c1xx : warning C4199: two-phase name lookup is not supported for C++/CLI, C++/CX, or OpenMP ...
- 【转载】Sql语句用left join 解决多表关联问题(关联套关联,例子和源码)
csdn中高手帮我给解决了,其实就是别名,给自己上了一堂别名的课,所谓别人是高手,其实就是自己是菜鸟吧! 表1:------------------------------ [人事表] 表名: ...
- layui使用小记(持续更新)
关于Select等Form表单元素,在使用的时候部分特性会失效 如select自带的Search功能: 其实在使用Form表单元素的时候,你如果需要layui自带的一些功能(搜索,验证等),请用< ...
- Nginx Location和Rewrite总结
Nginx 版本:nginx/1.10.3 (Ubuntu) Location 部分: 第一步:创建Nginx 虚拟主机 Nginx 安装成功安装并且可以运行之后,在 /etc/nginx 目录下创建 ...
- redis异常信息:MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk.。。。。
redis.exceptions.ResponseError: MISCONF Redis is configured to save RDB snapshots, but it is current ...
- Idea中配置svn时报 Can't use Subversion command line client: svn.Errors found while svn working copies detection.
https://www.cnblogs.com/wqh17/p/6881483.html
- URAL 1277 Cops and Thieves
Cops and Thieves Time Limit: 1000ms Memory Limit: 16384KB This problem will be judged on Ural. Origi ...
- python3--产生偏移和元素:enumerate
之前,我们讨论过通过range来产生字符串中元素的偏移值.而不是那些偏移值处的元素.不过,在有些程序中.我们两者都需要,要用的元素以及值个元素的偏移值.从传统意义来讲,这是简单的for循环,他同时也持 ...
- mysql与时间有关的查询
date(str)函数可以返回str中形如"1997-05-26"格式的日期,str要是合法的日期的表达式,如2008-08-08 22:20:46 时间是可以比较大小的,例如: ...
- Spring注解 @Component、@Repository、@Service、@Controller @Resource、@Autowired、@Qualifier 解析
@Repository.@Service.@Controller 这几个是一个类型,其实@Component 跟他们也是一个类型的 Spring 2.5 中除了提供 @Component 注释外,还定 ...