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.前言 最近项目中用到一个表格中对于相同内容的数据进行行合并的需求,本来想从网上找个现成的,省的自己再造轮子.于是就开始谷歌了...不过在搜索的过程中,发现找到的工具类很多都有一个前提,就是该表格中 ...
随机推荐
- Centos7安装tomcat(wget获取安装包)
选择要下载的版本去tomcat库查看想要下载的版本 https://mirrors.cnnic.cn/apache/tomcat/ 下载选择tomcat8的一个版本 wget https://mirr ...
- mysql两种常用备份工具
一.mysqldump备份: 在开启GTID模式时,在master上执行的备份: --set-gtid-purged=OFF 在开启GTID模式时,要在slave上执行,想重新搭建一套slave环境. ...
- transformer模型解读
最近在关注谷歌发布关于BERT模型,它是以Transformer的双向编码器表示.顺便回顾了<Attention is all you need>这篇文章主要讲解Transformer编码 ...
- Angular 1.x 框架原理
指令生命周期 compile阶段 对dom进行编译,首先(如果有的话)对template进行应用(这个过程只执行一次).然后把当前指令(内部的指令还没被渲染)传递给iElement,接着执行compi ...
- LeetCode(26) Remove Duplicates from Sorted Array
题目 Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- 3.3.2 使用 cut 选定字段
cut 命令是用来剪下文本文件里的数据,文本文件可以是字段类型或是字符类型.后一种数据类型在遇到需要从文件里剪下特定的列时,特别方便.请注意:一个制表字符在此被视为单个字符. ...
- Leetcode 236.二叉树的最近公共祖先
二叉树的最近公共祖先 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:"对于有根树 T 的两个结点 p.q,最近公共祖先表示为一个结点 x,满足 x ...
- Codeforces Round #387 (Div. 2) A+B+C+D!
A. Display Size 水题,暴力(数据都是水题).0:04 int main() { int n; while(~scanf("%d",&n)) { int mi ...
- Open Judge 3339 List
3339:List 总时间限制: 4000ms 内存限制: 65536kB 描述 写一个程序完成以下命令:new id ——新建一个指定编号为id的序列(id<10000)add id nu ...
- linux service命令解析(重要)
我们平时都会用service xxx start来启动某个进程,那么它背后究竟执行了什么? 其实service的绝对路径为/sbin/service ,打开这个文件cat /sbin/service, ...