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.前言 最近项目中用到一个表格中对于相同内容的数据进行行合并的需求,本来想从网上找个现成的,省的自己再造轮子.于是就开始谷歌了...不过在搜索的过程中,发现找到的工具类很多都有一个前提,就是该表格中 ...
随机推荐
- g++使用总结
学习C和C++的同学应该都知道,gcc是一款跨平台的C/C++编译器,可以在Linux/Windows平台下使用,具有十分强大的功能,结构也十分灵活,并且可以通过不同的前端模块来支持各种语言,如Jav ...
- 条款6:若不想使用编译器自动生成的函数,就该明确拒绝(Explicity disallow the use of compiler-generated functions you do not want)
class uncopyable{ protected: uncopyable(){}; ...
- h5 页面 禁止网页缩放
//禁用双指缩放: document.documentElement.addEventListener('touchstart', function (event) { if (event.touch ...
- php 复制文件夹
public function recurse_copy($src,$des) { $dir = opendir($src); @mkdir($des); while(false !== ( $fil ...
- sqlserver建dblink
--建立连接exec sp_addlinkedserver'ITSV' ,'' , 'SQLOLEDB' ,'IP地址不加端口' exec sp_addlinkedsrvlogin'ITSV' ,'f ...
- hdu 2831
#include<stdio.h> #include<stdlib.h> struct node{ int x,y,j,num; }a[110]; int cmp(const ...
- [转]eclipse的android智能提示设置
以往 我们往往在输入 "." 然后 alt+/ 来进行智能提示,下面这个方法,可以帮你大幅度的提高智能打开 Eclipse -> Window -> Perferenc ...
- php中memcache与memcached的区别 【收藏】
说法一: 两个不同版本的php的memcached的客户端 new memcache是pecl扩展库版本new memcached是libmemcached版本功能差不多 说法二: Mem ...
- 使用DataOutputStream输出流的read方法出现读取字节不一致解决办法,本地和测试环境不一致
之前: DataInputStream in = new DataInputStream(connection.getInputStream()); byte[] b = new byte[in ...
- 洛谷—— P1536 村村通
P1536 村村通 题目描述 某市调查城镇交通状况,得到现有城镇道路统计表.表中列出了每条道路直接连通的城镇.市政府“村村通工程”的目标是使全市任何两个城镇间都可以实现交通(但不一定有直接的道路相连, ...